1
我有一個VBS文件,我試圖用它來確定哪些文件夾和文件在某個目錄中。我相信我的代碼可以正確編寫,但每當我嘗試寫出文件或當前目錄時,我都會得到一個空白的文本文檔,只有根目錄已寫出。任何建議將不勝感激。創建一個能夠寫出文本文件的VBS文件
Dim NewFile
Function GetFolders (strFolderPath)
Dim objCurrentFolder, colSubfolders, objFolder, files
Set objCurrentFolder = objFSO.GetFolder(strFolderPath)
Set colSubfolders = objCurrentFolder.SubFolders
For Each objFolder In colSubfolders
NewFile.WriteLine(" - " & objFolder.Path)
Set files = folder.Files
For each folderIdx In files
NewFile.WriteLine(" - "& folderIdx.Name)
Next
Call GetFolders (objFolder.Path)
Next
End Function
Dim fso, sFolder
Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Quit
End If
Set NewFile = fso.CreateTextFile(sFolder&"\FileList.txt", True)
NewFile.WriteLine(sFolder)
Call GetFolders(sFolder)
NewFile.Close
謝謝你。我嘗試了Option Explicit方法,但仍然允許我的腳本文件在不返回錯誤的情況下運行。我在Notepad ++中這樣做,所以如果有另一個程序可以讓Option Explicit函數返回錯誤,我很樂意嘗試。 – Seb