VB 範例:列出 d:\temp 每一個 PDF 檔
Dim folderPath as String = "d:\temp"
Dim fileNames = My.Computer.FileSystem.GetFiles(
folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.pdf")
For Each fileName As String In fileNames
MessageBox(fileName)
Next
我剛好有一個取資料夾明細的範例,是用C#寫的,給您參考。
string rootpath = @"\\server8\Log";
string FileNoExt, FileWithExt = "";
string[] dirs = Directory.GetDirectories(rootpath);
foreach (string filepath in dirs)
{
string[] files = Directory.GetFiles(filepath);
foreach (string filename in files)
{
//filename=@"\\server8\Log\Dir1\abc.pdf"
//檔名(不包含副檔名)(不含路徑)例:abc
FileNoExt = Path.GetFileNameWithoutExtension(filename);
//檔名(包含副檔名)(不含路徑)例:abc.pdf
FileWithExt = Path.GetFileName(filename);
}
}