Batch question

  • Thread starter Thread starter Howard Brazee
  • Start date Start date
H

Howard Brazee

I have a .bat file that includes:

cd "%USERPROFILE%"

Trouble it, this doesn't work if I'm on the wrong logical drive. How
do I get to the correct drive if my user profile is unknown?
 
Try

cd %homepath%

or

cd %HOMEDRIVE%%HOMEPATH%

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
Well it does work. It does what it is supposed to, change the default directory on the specified drive. Try typing
cd /?
to see what else it can do.
 
Howard Brazee said:
I have a .bat file that includes:

cd "%USERPROFILE%"

Trouble it, this doesn't work if I'm on the wrong logical drive. How
do I get to the correct drive if my user profile is unknown?

When you type cd /? then you will immediately see that
the correct command in your case is

cd /d "%UserProfile%"
 
When you type cd /? then you will immediately see that
the correct command in your case is

cd /d "%UserProfile%"

That works.

If my userprofile is on F:, I can't do this.

C:
xcopy "m:\camera card\data" "%USERPROFILE%\Application Data\camera
card\data"

But I can do:
C:
cd /d "%UserProfile%"
xcopy "m:\camera card\data" "%USERPROFILE%\Application Data\camera
card\data"


I'd rather not have to be on the drive that has %USERPROFILE%, as
sometimes I want to be on the "from" drive.
 
Why can't you do it? XCopy has no requirements like this.

--

Indeed.

But this might happen if XCOPY.EXE is in the %USERPROFILE% directory but not
on the path or if there is some other XCOPY executable (like XCOPY.BAT for
instance) in your then-current directory on C:

I suspect you've called your batch file XCOPY.BAT or XCOPY.CMD

If you do this, executing XCOPY within the batch will locate XCOPY.BAT in
the current directory, and run that (which locates XCOPY.BAT in the current
directory .....) rather than running XCOPY.EXE (from the \windows\system32
directory) since the PATH is always implicitly prefixed by the current
directory name.

When you move to a different directory before attempting the XCOPY command,
XCOPY.BAT is no longer in the current directory, so the path is searched and
c:\windows\system32\XCOPY.EXE found

Just rename XCOPY.BAT so that the name part no longer conflicts with inbuilt
commands

HTH

....Bill
 
I don't know, that's why I asked. All I know is that when I am in
the wrong drive, the XCOPY command fails to find the file
%USERPROFILE% directory. When I am on the right drive, it finds it.

Indeed.

But this might happen if XCOPY.EXE is in the %USERPROFILE% directory but not
on the path or if there is some other XCOPY executable (like XCOPY.BAT for
instance) in your then-current directory on C:

I suspect you've called your batch file XCOPY.BAT or XCOPY.CMD

It's HOME.BAT.
 
Howard Brazee said:
It's HOME.BAT.

Have you tried explicitly nominating the path to XCOPY, ie in place of XCOPY
use

C:\windows\system32\xcopy

That might cure the problem.

HTH

....Bill
 
Back
Top