Jump to content

Batch won't change directories across drives


luke77

Recommended Posts

On a Vista System

I have this batch file on a thumb drive.

It works fine in a cmd.exe window, but not when executed from explorer.exe.

Does someone know how to make it work?

Vielen dank,

Andy

c:

cd\

cd Z0AA7~1

That dir /x is handy as a pocket. :-)

Link to comment
Share on other sites


I've tried successfuly this batch file from Explorer (desktop):

cd /D D:\Program Files
pause to see if errors

No space between the backslash and the folder name or directory name.

I've also tried to launch this batch file set inside an USB key and works fine (letter K:\).

Edited by myselfidem
Link to comment
Share on other sites

The clue is in the question.

CD will change the directory within a Prompt Window not within Windows Explorer.

To open an explorer window, you will need to use explorer.exe with its approipriate switche(s).

Try this:

XploreIt.cmd

@PUSHD %SYSTEMDRIVE%\
@FOR /F "TOKENS=4" %%# IN ('DIR/X/AD Z0*^|FIND "<DIR>"') DO @(
START EXPLORER /E,/ROOT,%%~f#)

Please ensure that you use a unique string after DIR/X/AD on line two, (I have used the first two characters from your posted directory name in my example, but not knowing the actual name means I had to guess, you may need something like *0AA*)

Link to comment
Share on other sites

The clue is in the question.

CD will change the directory within a Prompt Window not within Windows Explorer.

To open an explorer window, you will need to use explorer.exe with its approipriate switche(s).

Try this:

XploreIt.cmd

@PUSHD %SYSTEMDRIVE%\
@FOR /F "TOKENS=4" %%# IN ('DIR/X/AD Z0*^|FIND "<DIR>"') DO @(
START EXPLORER /E,/ROOT,%%~f#)

Please ensure that you use a unique string after DIR/X/AD on line two, (I have used the first two characters from your posted directory name in my example, but not knowing the actual name means I had to guess, you may need something like *0AA*)

I have been using this, but your solution looks more robust.

Andy

:: z.bat Help from alt.msdos.batch.nt Mic,Todd,Frank,

:: Traverse from different drives

:: dir /x utilized to determine the "secondary" directory name

::

%windir%\explorer.exe /e,/select,c:\Z0AA7~1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...