我创建了一个 VB 脚本以递归方式列出其所有文件和子文件夹文件。该脚本开始正常,但最终在包含文件名中包含不可打印字符的文件的任何文件夹中崩溃,即当我在资源管理器中浏览文件夹时看到小方块。我不确定如何更改以下错误处理以在找到具有此类字符的文件时继续。
任何建议或解决方案将不胜感激。谢谢你。
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\Input\"
Set objFolder = objFSO.GetFolder(strFolder)
Set NewFile = objFSO.CreateTextFile("C:\Output\" & objFolder.Name & " FileList.txt", True)
Set colFiles = objFolder.Files
On Error Resume Next
For Each objFile In colFiles
NewFile.WriteLine(objFile.Path)
If Err Then
Err.Clear
End If
Next
ShowSubFolders(objFolder)
Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
NewFile.WriteLine(objFile.Path)
If Err Then
Err.Clear
End If
Next
ShowSubFolders(objSubFolder)
Next
End Sub
NewFile.Close