vbscript - VBS: How to use %PROGRAMFILES% in objFSO.CopyFile? -
i trying re-create file objfso.copyfile command in vbs. problem is, can not utilize hard coded paths in company trying utilize variable. code, when utilize c:\program files\
instead of %programfiles%
works.
option explicit dim strfiletocopy dim strfolder dim objfso dim objwshell set objfso=createobject("scripting.filesystemobject") set objwshell=wscript.createobject("wscript.shell") strfiletocopy = "%programfiles%\mainfolder\subfolder\netcfg.ini" strfolder = "%programfiles%\othermainfolder\" const overwriteexisting = true set objfso = createobject("scripting.filesystemobject") if objfso.folderexists(strfolder) objfso.copyfile strfiletocopy, strfolder, overwriteexisting else end if
use .expandenvironmentstrings():
>> set objwshell=wscript.createobject("wscript.shell") >> wscript.echo objwshell.expandenvironmentstrings("%programfiles%\mainfolder\subfolder\netcfg.ini") >> c:\program files\mainfolder\subfolder\netcfg.ini >>
vbscript
No comments:
Post a Comment