Log in

View Full Version : How do I get the path of a .bat file inside the .bat file dynamically?


spa_m
Mar 22, 2007, 06:16 AM
Hi...

I have a .bat file (script) which I can place in any directory. How do I get the current directory path of this file inside this .bat file dynamically without initaly setting any variable? I know we can use "." or ".."etc.
But i know there is some command which we can use in the .bat file which will return the path where this .bat file is currently placed, but i dont know which one that is...
This command has a "~" symbol in it and i totally can't recollect what this command is.
Once i have the path of the directory where this current .bat file is placed i can then use this path at a later stage for either going to the top directory or something like that using "." or "..". Using this particular command will make my .bat file (script file) very generic.
Please do help me out

Spa

asterisk_man
Mar 22, 2007, 06:52 AM
This is windows I assume.
Look here for some good reference
Batch File Command Reference for Windows 2000 (http://labmice.techtarget.com/articles/batchcmds.htm)

You can use %~f0 for the full path to the current script. Hope that helps!

spa_m
Mar 23, 2007, 12:13 AM
Hiiiiii
Thanks this did help.
It actually gives the complete path of the bat file i.e. including the name of the bat file
I needed the path so I can further use this path and go to a required folder using "." or "..".
The link you gave is also helping. Thanks again.
A :) Spa

jaeope
Jul 8, 2010, 10:29 PM
Try %~dp0
That will not include the name of the bat file.
Hope it helps.

Shaibaz93
Jan 26, 2012, 11:43 PM
http://appsbazar.blospot.com

Type this url in Google and watch all things which you really want.. .