%~p0\
(or: Many times your batch file will want to access resources in the same folder as the batch file. This can be tricky if the user calls the batch file from another folder, since the working directory is not the directory the batch file is in. Rather that resorting to pushd / popd everywhere, one can use the extended command line parameter handling to convert the full path to the batch file into a relative path to it’s container. %0 is the path the batch was called with, so %~p0 is the path to that location)
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Summary: Even if you think you know what you're doing, it is not safe to store anything in a ThreadStatic member, CallContext or Thread...
-
I love PowerShell, and use it for pretty much everything that I’m not forced to compile. As a result I’ve got fairly competent, and people h...
-
Look, it’s really not that hard. Programs are still in the same place, in %ProgramFiles%, unless you need the 32 bit version, which is in...
3 comments:
Use %~pd0 instead if you want it to specify which disk as well, otherwise it will break if you're running the script from a different disk.
Indeed.
In fact what I'd been doing subsiquent to this post is wrapping most scripts in a pushd %~dp0 / popd pair. That way script resources can be accessed even when the script was executed via double-click from a file share (many commands won't take a UNC path, but pushd will).
But then I discovered Powershell...
Thanks! Helped me make a yui compressor batch file. (which compresses javascript files on my W: drive)
%~d0
cd %~p0
java -jar yuicompressor-2.4.2.jar --type js -v -o %1-compressed.js %1
Post a Comment