copy - Check if a folder exist and rename in vbscript -
okay here want do. script copies folder appdata folder on computer here need do. need check if folder of name exists , if rename else copy folder here current script need modify check if folder excists. thanx in advance
set oshell = createobject("wscript.shell") strhomefolder = oshell.expandenvironmentstrings("%appdata%") set oshell = createobject("wscript.shell") set ofso = createobject("scripting.filesystemobject") oshell.currentdirectory = ofso.getparentfoldername(wscript.scriptfullname) destinationfolder = strhomefolder & "\vlc" sourcefolder = oshell.currentdirectory & "\vlc" dim filesys set filesys=createobject("scripting.filesystemobject") if filesys.folderexists(sourcefolder ) filesys.copyfolder sourcefolder , destinationfolder end if
you detect whether destination folder exists same way detect whether source folder exists:
if filesys.folderexists(destinationfolder) 'do stuff end if
renaming folder can done e.g. this:
filesys.getfolder(destinationfolder).name = "othername"
there's no need change working directory you're doing, btw, , instantiating shell , filesystemobject objects twice.
you should change way construct source , destination paths, though. fiddling around path separators prone error. it's better use buildpath
method constructing paths:
destinationfolder = ofso.buildpath(oshell.expandenvironmentstrings("%appdata%"), "vlc") sourcefolder = ofso.buildpath(ofso.getparentfoldername(wscript.scriptfullname), "vlc")
with script this:
set sh = createobject("wscript.shell") set fso = createobject("scripting.filesystemobject") dst = fso.buildpath(sh.expandenvironmentstrings("%appdata%"), "vlc") src = fso.buildpath(fso.getparentfoldername(wscript.scriptfullname), "vlc") if fso.folderexists(src) if fso.folderexists(dst) fso.getfolder(dst).name = "othername" fso.copyfolder src, dst end if
Comments
Post a Comment