commands are run alwais in root path (c:\ d:\ ...)

  • Thread starter Thread starter Oliver Rasto
  • Start date Start date
O

Oliver Rasto

Hi,

when i create a bat file in any folder (for example
c:\applications\mybat.bat) and i run it in this directory the bat always
thinks it is running in the root directory of the drive from where i have
invoked it.

So when the command in the .bat file is for example 'dir' the output is
always

C:\applications\mybat.bat

Volume in drive C is SEAGATE160
Volume Serial Number is 8B5C-3C62

Directory of C:\
.... following the content of C:\ drive ...

what can be wrong?

Thanks.
 
Hi,

when i create a bat file in any folder (for example
c:\applications\mybat.bat) and i run it in this directory the bat always
thinks it is running in the root directory of the drive from where i have
invoked it.

So when the command in the .bat file is for example 'dir' the output is
always

C:\applications\mybat.bat

Volume in drive C is SEAGATE160
Volume Serial Number is 8B5C-3C62

Directory of C:\
... following the content of C:\ drive ...

what can be wrong?

Nothing is wrong. The "current folder" is a system setting stored for
each drive. The "current drive" is a further system setting that is
stored for the entire system. Merely running the command:

C:\applications\mybat.bat

doesn't change the current folder or drive unless mybat.bat specifically
contains commands that do so.

First type the command (without arguments):

CD

to see what the current drive and folder are. Any commands in your
batch file that need a path (but don't specify one) will use the current
drive and whatever folder is current for that drive as their default path.

Either specify a path for your DIR commands, or make the drive and
folder on which the Batch file is located become the current ones.

Typical syntax to make a Batch file's drive and folder current:

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
ECHO. This Batch file is in folder: %~p0
ECHO. This Batch file is on drive: %~d0
ECHO. Now making that drive and folder current...
CD /d %~dp0
DIR

====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects

For help with CD use the /? switch:
cd /?

For more details of %~[letter] variables available, read the /? help
under FOR:
for /?
 
Oliver Rasto said:
Hi,

when i create a bat file in any folder (for example
c:\applications\mybat.bat) and i run it in this directory the bat always
thinks it is running in the root directory of the drive from where i have
invoked it.

So when the command in the .bat file is for example 'dir' the output is
always

C:\applications\mybat.bat

Volume in drive C is SEAGATE160
Volume Serial Number is 8B5C-3C62

Directory of C:\
... following the content of C:\ drive ...

what can be wrong?

If the only command in the batch is DIR, then the output above does not
appear to be correct. It appears there is an "ECHO %0" command preceding the
DIR command. Please indicate how you ran the batch.

Note, if you are typing the command in the RUN box, or if you are clicking
on the batch in explorer, then you need to specifically state that
information.
 
Back
Top