We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

changing directory in bat file

Tagom
Tagom asked
on
Medium Priority
802 Views
Last Modified: 2012-06-21
I am working on creating a bat file/script
what i need to do at the end of the file is change to another directory.
Current code:

suggestions on how I can get this to work....currently the result is to stay in the
cd "d:\test\..\Java\jasperserver-ce-3.7.0\scripts"
directory
@echo off
@echo off
cScript.exe //B //Nologo "d:\test\Shared\WriteMUSLog.vbs" "d:\test" JasperServer.bat "jsUnzip.bat [Start]"

if exist "\java\jasperreports-server-cp-4.0.0" exit

cScript.exe //B //Nologo "d:\test\Shared\WriteMUSLog.vbs" "d:\test" JasperServer.bat "jsExport.bat [Start]"

echo Exporting Repository to D:\test\JasperServer\Repository_updated (users, connections, a test report, etc.)  Please wait...

cScript.exe //B //Nologo "d:\test\Shared\WriteMUSLog.vbs" "d:\test" JasperServer.bat "exporting Jasper Repository"

cd "d:\test\..\Java\jasperserver-ce-3.7.0\scripts"
js-export --everything  --output-dir D:\test\JasperServer\Repository_updated >> "d:\test\Logs\Installation\JasperServer.log" 2>&1

CHDIR "d:\test"

Open in new window

Comment
Watch Question

I do not completely understand at what folder you'd like to end with.
d:\test OR d:\test\..\Java\jasperserver-ce-3.7.0\scripts

another thing, in your command you use .. in the path. that means go 1 folder down.
so basically if I'm in the folder (for example) d:\test and I type cd d:\..\test, I'll stay in the same folder.

Thanks

Commented:
How about just putting "CD\" to take yourself back to D:. then "CD TEST" to go into the test directory?
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
If your script is started from any drive other than D:, any "cd D:\..." will not work as you expect it to; I suspect that the "cd" in line 13 isn't working, either.
You can either use complete paths (recommended), or always use "cd /d" which will change the directory as well as the drive:
cd /d "d:\test\..\Java\jasperserver-ce-3.7.0\scripts"
js-export --everything  --output-dir D:\test\JasperServer\Repository_updated >> "d:\test\Logs\Installation\JasperServer.log" 2>&1
CHDIR /d "d:\test"

Open in new window

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
perfect thanks
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.