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 🙂 )
Categories: Windows
batch file, cd, change directory, change drive, chdir, shell script, Windows
Thanks 😉
found this off a google search. I have some batch files I inherited. Making the scripts more dynamic by using the subst command. So now the full path has a drive letter in it, whereas it used to just change to a sub directory. Probem is, it wasnt’ actually changing directories when I do an echo %cd% for the current directory.
Adding the /d to a cd (chdir) command did the trick!
Thank you so much this really helped me out!!
Thanks a ton, was making a batch file lanuncher but wasnt able to change drives, thanks.
Thank you for posting this steps. It solved my problem !!!
Работаю с этим сайтом http://obnalmc.blogspot.com/.
Рекомендую. Все честно.
On a Windows 2008 server the root directory is C:Users/username/desktop. I cannot get a batch file to change the directory to the data drive (e:) regardless if i use \D, CD.., Pushd, setlocal or any other command. File:
cmd
SETLOCAL
CD ..
CD /D “e:\Sync Tool\programfolder\programsubfolder
Is there somthing about the “Users” Folder in Windows that I don’t understand??
It is kind of reinventing the wheel 🙂 Check pushd/popd commands. They will do the trick without need of storing values in local vars
https://technet.microsoft.com/en-us/library/bb490978.aspx
Kulitnya putih bersih, dengan betis yang woow, berambut menantang pastilah perempuan indah ini
punya nafsu seksual yang liar, itu kata temanku yang pengalaman seksnya tinggi Buah dadanya terlihat menyembul dari balik gaun tidur
itu, apalagi ketika dia melangkah di sampingku, samar-samar dari sudut mataku menonjol cantik payudaranya yang putih lembut
“Uh , apa ini gara-gara film itu?”, batinku lagi
Imajinasi bos aon338 mulai kurang didik, atau selama ini saya mengamati
cs senantiasa mengaplikasikan kutang seksi dan berhijab jadi saya tak
tahu wujud tubuhnya yang hakekatnya, segera saya
memasukkan bayang-bayang ke dalam adegan film tadi
“Hmm ”, tidak sadar mulutku mengeluarkan bunyi itu
“Ada apa, Di?”, isteri bos aon338 itu memandangku dengan alis berkerut
“Eh , kau ngelamun yah, ngelamunin siapa sih? cs yang
seksi?”, tanyanya
memperhatikan cs seksi dada bos dan leader aon338 berdesir
sesaat pandangan mataku tertuju pada belahan dadanya