C# 獲取一個資料夾下的所有檔案
public static List<string> m_fileList = new List<string>();
public static int GetDirectory(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //獲取目錄下(不包含子目錄)的檔案和子目錄
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判斷是否資料夾
{
GetDirectory(i.FullName); //遞迴呼叫複製子資料夾
}
else
{
m_fileList.Add(i.FullName);
}
}
return 0;
}
catch (Exception e)
{
return -1;
}
}