我发现此代码排除了特定的文件夹名称,但我需要根据'以'开头的文件夹名称进行排除。
(例如admin%)如何以这种方式重写?
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
If objSubfolder.Name <> "All Users" And objSubfolder.Name <> "Default" _
And objSubfolder.Name <> "Default User" And objSubfolder.Name <> "Public" Then
WScript.echo objSubfolder.Name
End If
Next
答案 0 :(得分:0)
请检查这是否是您所需要的。
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
If InStr(1,objSubfolder.Name, "admin") <= 0 Then
WScript.echo objSubfolder.Name
End If
Next
上述脚本应排除以 admin 开头或包含 admin 的所有文件夹。但它的情况很敏感。如果您需要使其不区分大小写,请使用以下脚本。
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
If InStr(1,objSubfolder.Name, "admin",1) <= 0 Then
WScript.echo objSubfolder.Name
End If
Next