Dir of .bat file in variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chill
Posts: 1
Joined: 14 Jan 2009 08:14

Dir of .bat file in variable

#1 Post by chill » 14 Jan 2009 08:21

hi how do I get the dir of the started .bat file in a varaible?
%0 saves the pfad + file name. thx

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 16 Jan 2009 01:04

chill,

If for example your batch file is at c:\dostips\chill\mybatch.cmd then:

set fullname=%~f0
set name=%~n0
set extension=%~x0
set drive=%~d0
set folder=%~p0
set driveAndFolder=%~dp0

will set the variables as follows:

fullname will be: c:\dostips\chill\mybatch.cmd
name will be mybatch
extension will be .cmd
drive will be c:
folder will be \dostips\chill\
driveAndFolder will be c:\dostips\chill\

DosItHelp? :wink:

Post Reply