public static string[] GetLogicalDrives()

1. namespace : System
2. 반환 값 : 각 요소에 논리 드라이브의 이름이 들어 있는 문자열의 배열. 예를 들어 컴퓨터의 하드 드라이브가 첫 번째 논리 드라이브일 경우, 반환되는 첫 번째 요소는 "C:\"
3. 예외
- IOExceptionI/O :     오류가 발생하는 경우
- SecurityException : 호출자에게 필요한 권한이 없는 경우

using System;

class Sample
{
  public static void Main()
  {
       Console.WriteLine();
       String[] drives = Environment.GetLogicalDrives();
       Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
  }
}

결과 : "GetLogicalDrives: A:\, C:\, D:\"
출처 : MSDN


-------------------------------------------------------------------------------------

public string ReturnDir()
{

string OutputPath = string.Empty;
string innerPath = string.Empty;
string[] sar  = Environment.GetLogicalDrives();


for( int i = 0; i < sar.Length; i++ )
{

string path = sar[i].ToString() + "examplePath";

dir = new DirectoryInfo( path );
       
if( !dir.Exists ) // == false
{

path = string.Empty;
dir = null;

}
else
{

innerPath = sar[i].ToString() + "examplePath";

dir = null;

}

}


OutputPath = innerPath

return OutputPath;

}

+ Recent posts