Having to Change the Drive constantly in Batch script -
i have come across odd behaviour batch script haven't seen before.
below have had script work. below piece of overall script shows issue. in short having switch drives in code. becomes issue when using blat.exe attachment on different drive.
set datafile=test%date:~-7,2%%date:~-10,2%.csv :: echos correct name echo %datafile% :: wouldn't expect need 2 lines below d: cd %datapath% :: if file not present exit if not exist %datafile% ( echo no file exists exit )
what want able simplify things (what on other environments)
set datafile=test%date:~-7,2%%date:~-10,2%.csv :: echos correct name echo %datafile% :: if file not present exit if not exist %datafile% ( echo no file exists exit )
hopefully makes sense. seems environment issue or similar, cant find obvious.
thank help.
edit solution:
as mentioned in comment below, underlying issue sent me on complete wild goose chase , hence example provided made little no sense. problem comment inside of if statement excluded examples provided keep things clean. turned out comment problem!
the below not work , complains missing ')'
if not exist %filepath%\%filename% ( echo file not exist :: call {path executable} ) .. continue script
the script below work
if not exist %filepath%\%filename% ( echo file not exist ) :: call {path executable} .. continue script
thanks issue.
one thing quoting both path1
, file1
when assign them value. cause problem when dealing full paths:
move %path1%%file% %path2%
expands (using values):
move "path1""file1" "path2"
instead not quote paths , file name concatenated later, rather quote them when combined:
set path1=c:\my path\ set file1=myfile.txt set path2="c:\new path\" rem combined path quoted. move "%path1%%file%" %path2%
the above expands to:
move "c:\my path\myfile.txt" "c:\new path\"
for full script, try this:
rem not quote path/files combined. set path1=path1 set file1=file1 set path2="path2" rem quote path here since isn't quoted in declaration. if not exist "%path1%" ( md "%path1%" ) rem combined path quoted. move "%path1%%file%" %path2% ::exe below on drive call [path_to_exe].exe
Comments
Post a Comment