vbscript - Need to compare folder path in VBS (.regex) -
question is: need compare folder1
path , folder2
path strings in vbs.
folder1
read text file, saved earlier. folder2
- select folder dialog. want prevent user choose folder2
if:
folder2 = folder1
folder2 = folder1\some_folder
folder2 = parent_folder\folder1
for example: folder1 = c:\users\user\documents
folder2
cannot be: c:\users\user\documents
, c:\users\user\documents\letters
or c:\users\user\
cannot make right regex compare. right use following code, need normal solution.
rightpath = 0 set objshell = createobject("shell.application") set objfolder = objshell.browseforfolder(0, "select folder:", &h10&, strpath) if objfolder nothing msgbox "configuration canceled" ,64 , "information" wscript.quit end if set objfolderitem = objfolder.self objpath = objfolderitem.path ' right now, check users folder rightpath = rightpath + 1 dim re, targetstring set re = new regexp re .pattern = "desktop|documents|downloads|music|pictures|videos" .global = false .ignorecase = true end targetstring = objpath if re.test(targetstring) msgbox "you cannot choose:" & vbcrlf & vbcrlf & _ "desktop, documents, downloads, music, pictures or videos" & vbcrlf & vbcrlf & _ "please select location" ,48 , "warning!" rightpath = 0 end if loop until rightpath > 0 msgbox "you selected "+targetstring ,0 , "information," wscript.quit
if can't of these: c:\users\user\documents, c:\users\user\documents\letters
or c:\users\user\
instr
might first two.
for example,
folder1 = "c:\users\user\documents" folder2 = "c:\users\user\documents\letters" if instr(folder2,folder1) fail
if didn't want part of user input same folder1 reverse order of instr
check.
if need more specific this, might have split folder strings arrays (split "\") compare first x number of fields in array.
Comments
Post a Comment