changing directory in bat file

Posted on 2011-04-25
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"
@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

Question by:Tagom
    LVL 3

    Expert Comment

    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.

    LVL 6

    Expert Comment

    How about just putting "CD\" to take yourself back to D:. then "CD TEST" to go into the test directory?
    LVL 82

    Expert Comment

    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

    LVL 51

    Accepted Solution

    What I'm hearing is that after executing:

    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

    You are in the "d:\test" directory as the default.  This makes me thing the final CD never got executed, and this would typicall happen if the js-export didn't return control to the calling batch file.  I suspect that js-export is implemented as a BAT file, which would indeed cause this problem.  Give the following a try and see if it works better.

    cd "d:\test\..\Java\jasperserver-ce-3.7.0\scripts"
    call 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


    Author Closing Comment

    perfect thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    The Display applet of Windows 7 Control Panel has changed a great deal since Windows XP  (it was missing and more or less replaced in Windows Vista by the Personalization applet.)  Below is a screenshot of what the Display applet of Windows XP, whic…
    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now