batch file - getting working directory

Sharky Forums


Results 1 to 6 of 6

Thread: batch file - getting working directory

  1. #1
    Hammerhead Shark
    Join Date
    Feb 2001
    Posts
    1,612

    batch file - getting working directory

    ok, I've got a windows xp batch file (.cmd) i'm working on, but I don't know how to store the current working directory. (i.e. $PWD in bash) Here's all I could think of, based on the windows help:

    cd | set /p pwd=

    but that doesn't seem to do anything.

  2. #2
    Great White Shark
    Join Date
    Nov 2000
    Posts
    21,595
    Pushd will store the current working directory. When you want to go back to it you do a popd.

  3. #3
    Hammerhead Shark
    Join Date
    Feb 2001
    Posts
    1,612
    hey that'll be perfect, that's exactly what i wanted it for.

    edit: Or, wait a minute, That actually wouldn't work. I want something like this:

    cd %1
    %root%\program.exe
    Last edited by Strogian; 09-05-2004 at 01:28 PM.

  4. #4
    Great White Shark
    Join Date
    Nov 2000
    Posts
    21,595
    Explain with a few more details what you are attempting to do.

    From what I can see if program.exe is in the path, there is no need for %root%. If %root% is user specified, it can be passed with %2, etc.

  5. #5
    Hammerhead Shark
    Join Date
    Feb 2001
    Posts
    1,612
    Right, I have abbreviated things a bit. Maybe this will be more clear:

    I can tell you right now that, unless there is a way to retrieve the current working directory, these are the options I will have:

    run it like this:
    cd \bob\joe\john\programfolder
    program \bob\joe\john\programfolder subdir1 subdir2 subdir2\subdir3

    , and in the batch file:
    cd %2
    %1\program *.asd


    or run it like this: (which is what I'd want
    cd \bob\joe\john\programfolder
    program subdir1 subdir2 subdir2\subdir3

    , but a bit messy in the batch file:
    copy program datafile1 datafile2 datafile3 %2
    cd %2
    program *.asd
    del program datafile1 datafile2 datafile3


    That isn't exactly what I'm doing, but has exactly the same requirements. If you could come up with a better third alternative, that would be awesome.

  6. #6
    Great White Shark
    Join Date
    Nov 2000
    Posts
    21,595
    I've got to shut down for Frances. I'll try to get back to you in a day or two. You'll get more help in the coding & scripting forum so I'm moving this thread there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •