回复 11# ghost-jason
上面那段是函数,不是程序。如果你在末尾加下面一句,那他就是一个扫描D:的实例程序(请以 CScript.exe 脚本.vbs 的方式运行):Call Demo("D:\")COPY 如果不是对文件数目很大的目录扫描,可以使用下面的代码(同时也是一个实例程序): | Dim strPath | | strPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%USERPROFILE%") | | WScript.Echo ScanFolder(strPath) | | | | Function ScanFolder(ByVal strPath) | | Dim arr() | | ReDim Preserve arr(0) | | Call SCAN_FOLDER(arr, strPath) | | ReDim Preserve arr(UBound(arr) - 1) | | ScanFolder = Join(arr, vbCrLf) | | End Function | | Function SCAN_FOLDER(ByRef arr, ByVal folderSpec) | | On Error Resume Next | | Dim fso, objItems, objFile, objFolder | | Set fso = CreateObject("Scripting.FileSystemObject") | | Set objItems = fso.GetFolder(folderSpec) | | If Right(folderSpec, 1) <> "\" Then folderSpec = folderSpec & "\" | | If (Not fso.FolderExists(folderSpec)) Then Exit Function | | For Each objFile In objItems.Files | | arr(UBound(arr)) = objFile.Path | | ReDim Preserve arr(UBound(arr) + 1) | | Next | | For Each objFolder In objItems.subfolders | | Call SCAN_FOLDER(arr, objFolder.Path) | | Next | | arr(UBound(arr)) = folderSpec | | ReDim Preserve arr(UBound(arr) + 1) | | End FunctionCOPY |
|