Ask Experts Questions for FREE Help!
 

Free Answers in 3 Easy Steps

Register Now
3 Steps
 


Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.
  View Answers    Answer this question    Ask a question  
 

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 don't 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, 10:43 PM
http://appsbazar.blospot.com

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