if statement - batch file to check existance of directory if not exists then use alternate directory for file copy -
i trying write batch file copies exe file network location local location. works depending on windows version (xp or win7) user has select correct .bat file due different local paths needed copy. (they going startup folder ran every time user starts machine). first time i've ever worked writing batch files , lost when looking @ syntax if statements. if figuring out great.
here have works xp:
rem @echo off echo starting movefiles set exitrc=0 set exitmsg=exitrc initialized echo %exitrc% -- %exitms copy "\\networkdrive\install\individual\program\movefiles.exe" "c:\documents , settings\all users\start menu\programs\startup\" echo copied files pc set exitrc=%errorlevel% if not %exitrc% == 0 goto :exit set exitmsg=processing complete :exit echo step: %exitmsg% rc: %exitrc% echo finishing movefiles pause exit %exitrc%
here have windows 7:
@echo off echo starting movefileswin7 set exitrc=0 set exitmsg=exitrc initialized echo %exitrc% -- %exitms copy "\\networkdrive\install\individual\program\movefiles.exe" "c:\programdata\microsoft\windows\start menu\programs\startup" echo copied movefileswin7 pc - users / public startup folder set exitrc=%errorlevel% if not %exitrc% == 0 goto :exit set exitmsg=processing complete :exit echo step: %exitmsg% rc: %exitrc% echo finishing movefileswin7 pause exit %exitrc%
i have 1 batch file cover both scenarios there no confusion user on batch file run.
you can utilise environment variable %allusersprofile%
.
on winxp default c:\documents , settings\all users
on win7/2008 default c:\programdata
there table available here: http://ss64.com/nt/syntax-variables.html
i see copy different file. not sure why that. maybe detect using method here: https://stackoverflow.com/a/2788764/1553090 -- otherwise perhaps should take advantage of %programfiles%
, %programfiles(x86)%
variables.
just elaborate on how might choose use these variables... can test win7 startup folder existence, , if it's not there fallback xp (regardless of whether exists).
set startup_win7=%allusersprofile%\microsoft\windows\start menu\programs\startup set startup_winxp=%allusersprofile%\start menu\programs\startup if exist "%startup_win7%" ( set startup=%startup_win7% ) else ( set startup=%startup_winxp% )
Comments
Post a Comment