Changing Directory in Windows Batch File
Just noticed a small thing yesterday.
set curr_dir=%cd% chdir /D J:\ REM...do your stuff... chdir /D %curr_dir%
notice two important things here:
- The script changes the current working directory to whatever it requires but then switches it back again so that if the user runs the script from a command window he is does not find himself in a strange directory after the script is finished
- There is a /D switch that needs to be added to chdir so that it changes the drive if required. Without this chdir won’t work ( it had me baffled for quite some time🙂 )