2009/04/02

c# 取得檔案列表

// Dir folder
public bool FileList(string folderName)
{
try
{
DirectoryInfo dirinfo = new DirectoryInfo(folderName);

FileInfo[] sortList = dirinfo.GetFiles();
string[] dirList = new string[sortList.Length];
string[] fileName = new string[sortList.Length];


for (int i = 0; i < sortList.Length; i++)
{
dirList[i] = sortList[i].Name.ToString();
fileName[i] = sortList[i].FullName.ToString();


}

FullFileName = fileName;
FileName = dirList;

return true;
}
catch (Exception ex)
{
_errorMessage = ex.ToString();
return false;
}

}

沒有留言: