질문 : FOLDER1
경로와 FOLDER2
경로 문자열을 VBS에서 비교해야합니다.VBS (.regex)에서 폴더 경로를 비교해야합니다.
FOLDER1
텍스트 파일에서 읽었습니다. 이전에 저장되었습니다. FOLDER2
- 폴더 선택 대화 상자에서. 내가 FOLDER2
경우 선택하는 사용자를 방지하려면 : c:\users\user\Documents
, c:\users\user\Documents\Letters
또는
c:\users\user\
잘 정규식 비교할 수 없습니다 : 예를 들어
FOLDER2 = FOLDER1
FOLDER2 = FOLDER1\some_folder
FOLDER2 = Parent_Folder\FOLDER1
: Folder1 = c:\users\user\Documents
다음 Folder2
가 될 수 없습니다. 지금 다음 코드를 사용하지만 정상적인 솔루션이 필요합니다.
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
예. 고맙습니다. InStr이 작동합니다. – MVKozyrev