Function FindAllFiles(FolderPath)Dim AllFiles,fso,Folder,f,filesAllFiles = ""Set fso = CreateObject("Scripting.FileSystemObject")Set Folder = fso.getfolder(FolderPath)Set files = Folder.filesFor Each f In filesAllFiles = AllFiles & f.name & ","NextSet fso = NothingFindAllFiles = Split(AllFiles, ",")End Function//下面是呼叫方法:FileEx = FindAllFiles(檔案路徑) //檔案路徑是字串,要加雙撇If UBound(FileEx) > 0 ThenFor i = 0 To UBound(FileEx) - 1MessageBox FileEx(i)NextElseMessageBox "資料夾沒有檔案"End If
Function FindAllFiles(FolderPath)Dim AllFiles,fso,Folder,f,filesAllFiles = ""Set fso = CreateObject("Scripting.FileSystemObject")Set Folder = fso.getfolder(FolderPath)Set files = Folder.filesFor Each f In filesAllFiles = AllFiles & f.name & ","NextSet fso = NothingFindAllFiles = Split(AllFiles, ",")End Function//下面是呼叫方法:FileEx = FindAllFiles(檔案路徑) //檔案路徑是字串,要加雙撇If UBound(FileEx) > 0 ThenFor i = 0 To UBound(FileEx) - 1MessageBox FileEx(i)NextElseMessageBox "資料夾沒有檔案"End If