"Oliver Rasto" wrote in message
> 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 /?
--
William Allen
Free interactive Batch Course
http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples
http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at
http://www.allenware.com/