问题是:我需要比较VBS 中的FOLDER1
路径和FOLDER2
路径字符串。
FOLDER1
我从文本文件中读取,它是之前保存的。FOLDER2
- 从选择文件夹对话框。我想阻止用户选择FOLDER2
是否:
FOLDER2 = FOLDER1
FOLDER2 = FOLDER1\some_folder
FOLDER2 = Parent_Folder\FOLDER1
例如:
Folder1 = c:\users\user\Documents
thenFolder2
不能是: c:\users\user\Documents
,c:\users\user\Documents\Letters
或c:\users\user\
无法制作正确的正则表达式进行比较。现在使用以下代码,但需要正常的解决方案。
RightPath = 0
Do
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Select folder:", &H10&, strPath)
If objFolder Is Nothing Then
msgbox "Configuration canceled" ,64 , "Information"
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
' Right now, Check for users folder only
RightPath = RightPath + 1
Dim re, targetString
Set re = New RegExp
With re
.Pattern = "Desktop|Documents|Downloads|Music|Pictures|Videos"
.Global = False
.IgnoreCase = True
End With
targetString = objPath
If re.Test(targetString) Then
msgbox "You cannot choose:" & vbCrLf & vbCrLf & _
"Desktop, Documents, Downloads, Music, Pictures or Videos" & vbCrLf & vbCrLf & _
"Please select another location" ,48 , "Warning!"
RightPath = 0
End If
Loop Until RightPath > 0
msgbox "You selected "+targetString ,0 , "Information,"
Wscript.Quit