VBS读文件夹问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 06:19:20
用VBS做一个脚本,实现:
有一个文件夹名字是(网络游戏),在它里面有N多个文件夹(例如:QQ游戏.跑跑.梦幻西游.........很多个)。我想要做的是 逐个检查这个子文件夹里是否有1.txt的文本文件,如果没有这个文件,则Msgbox "无",如果有,则检查下一个文件夹。全检查完毕,Msgbox "检查完毕"。
希望高手给解答!!!小弟分不多就给30吧!在次谢过了!
感谢 fastslz 回答

如何只显示出来 文件夹名呢?

On Error Resume Next
Set Fso = CreateObject("Scripting.FileSystemObject")
objFolder = CreateObject("WScript.Shell").CurrentDirectory
ShowFolders Fso.GetFolder(objFolder)
MsgBox "检查完毕"
Function ShowFolders(Folder)
For Each Subfolder in Folder.SubFolders
'WScript.Echo Subfolder.Path
If Not (Fso.FileExists(Subfolder.Path & "\1.txt")) Then
MsgBox Subfolder.Path & " 文件夹里无1.txt"
End If
ShowFolders Subfolder
Next
End Function

我写的那个不管用吗?

''保存为vbs放在(网络游戏)文件夹里

Dim aFiles,aFolders.Fso
On Error Resume Next
Set Fso = CreateObject("Scripting.FileSystemObject")
objFolder = CreateObject("WScript.Shell").CurrentDirectory
ShowFolders Fso.GetFolder(objFolder)
MsgBox "检查完毕"
Function ShowFolders(Folder)
For Each Subfolder in Folder.SubFolders
'WScript.Echo Subfolder.Path
If Not (Fso.FileExists(Subfolder.Path & "1.txt")) Then
MsgBox Subfolder.Path & " 文件夹里无1.txt"
End If
ShowFolders Subfolder
Next
End Function

补充回答:代码里Subfolder.Path就是文件夹名
MsgBox Subfolder.Path & " 文件夹里无1.txt"
改成
MsgBox Subfolder.Path