I am trying to create a right-click context menu command to compress JavaScript files using the YUI compressor. My ultimate goal is to try to run this in the context menu:
java.exe -jar yuicompressor-2.4.2.jar -o <filename>.min.js <filename>.js
I know that I can use the variable %1 to refer to the file name being opened. I cannot figure out how to get this command in the syntax of a batch file and could not find the answers on the Internet.
Update:
Jeremy's answer (+ comments) worked. For those who stumble upon this, here is what I need to do:
In the action that I created for the JavaScript file, I used this as a command:
minify.bat "%1"
Which calls my script package, which looks like this:
java.exe -jar yuicompressor-2.4.2.jar -o "%~dpn1.min.js" %1
For the script package, keep in mind that the above code assumes that the directories for java.exe and yuicompressor are added to your PATH variables. If you do not add them to your path, you will have to use the full path for the files.
The sequence %~dpn used to get:
%~d - Drive%~p - Path%~n - File Name
command-line windows batch-file
Dan Herbert Sep 24 '09 at 14:45 2009-09-24 14:45
source share