티스토리 뷰
class FileSysInfo { static void Main() { // You can also use System.Environment.GetLogicalDrives to // obtain names of all logical drives on the computer. System.IO.DriveInfo di = new System.IO.DriveInfo(@"C:\"); Console.WriteLine(di.TotalFreeSpace); Console.WriteLine(di.VolumeLabel); // Get the root directory and print out some information about it. System.IO.DirectoryInfo dirInfo = di.RootDirectory; Console.WriteLine(dirInfo.Attributes.ToString()); // Get the files in the directory and print out some information about them. System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.*"); foreach (System.IO.FileInfo fi in fileNames) { Console.WriteLine("{0}: {1}: {2}", fi.Name, fi.LastAccessTime, fi.Length); } // Get the subdirectories directly that is under the root. // See "How to: Iterate Through a Directory Tree" for an example of how to // iterate through an entire tree. System.IO.DirectoryInfo[] dirInfos = dirInfo.GetDirectories("*.*"); foreach (System.IO.DirectoryInfo d in dirInfos) { Console.WriteLine(d.Name); } // The Directory and File classes provide several static methods // for accessing files and directories. // Get the current application directory. string currentDirName = System.IO.Directory.GetCurrentDirectory(); Console.WriteLine(currentDirName); // Get an array of file names as strings rather than FileInfo objects. // Use this method when storage space is an issue, and when you might // hold on to the file name reference for a while before you try to access // the file. string[] files = System.IO.Directory.GetFiles(currentDirName, "*.txt"); foreach (string s in files) { // Create the FileInfo object only when needed to ensure // the information is as current as possible. System.IO.FileInfo fi = null; try { fi = new System.IO.FileInfo(s); } catch (System.IO.FileNotFoundException e) { // To inform the user and continue is // sufficient for this demonstration. // Your application may require different behavior. Console.WriteLine(e.Message); continue; } Console.WriteLine("{0} : {1}",fi.Name, fi.Directory); } // Change the directory. In this case, first check to see // whether it already exists, and create it if it does not. // If this is not appropriate for your application, you can // handle the System.IO.IOException that will be raised if the // directory cannot be found. if (!System.IO.Directory.Exists(@"C:\Users\Public\TestFolder\")) { System.IO.Directory.CreateDirectory(@"C:\Users\Public\TestFolder\"); } System.IO.Directory.SetCurrentDirectory(@"C:\Users\Public\TestFolder\"); currentDirName = System.IO.Directory.GetCurrentDirectory(); Console.WriteLine(currentDirName); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }
'P rogramming > E tc' 카테고리의 다른 글
| 네트워크 드라이브 자동 연결된 아이디 해제 방법. (0) | 2014.06.18 |
|---|---|
| 해당 운영체제의 bit 수 확인 법 두가지 - 닷넷 or 공용 (0) | 2013.11.13 |
| comdlg32.ocx could not found 에러 해결 (0) | 2013.08.30 |
| VB6KO.DLL could not be found 에러 해결 방법. (0) | 2013.08.30 |
| C# filesysinfo (0) | 2013.08.14 |
| C# 정리되지 않은 코드들 (0) | 2013.07.26 |
| 프로그래밍 기법 (0) | 2013.07.24 |
| cmd] 창의 결과를 파일로 저장 (0) | 2013.06.13 |
댓글
공지사항
최근에 올라온 글
- Total
- 331,919
- Today
- 0
- Yesterday
- 89
링크
TAG
- 알프스목초지1-4
- Joseph Redmon
- 리눅스
- C# 패널
- 자신만의향
- PolyBridge1-4
- DaleEvans
- C# 패널 예제
- PolyBridge1-3
- 믿는다는것
- 알프스목초지1-3
- PolyBridge1-5
- PolyBridge하는법
- 인생의시간
- 알프스목초지1-2
- PolyBridge1-1
- OnlyICan
- 분할작업
- Nina Fedoroff
- 1Day1Sentence
- c#
- 알프스목초지1-1
- 사람의인생
- ted
- PolyBridge
- 좋은글귀
- 알프스목초지1-5
- PolyBridge1-2
- 폴리브릿지
- C# 판넬 예제
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
글 보관함
- 2017/08 (4)
