Windows command line tricks

Just a quick one, since I just discovered this. (Apparently I’m slow!)

You all probably know, in a windows batch file, you can do something like this:

@echo off
echo first %1
echo second %2
echo rest %*

which will give you:

c:\>test.cmd john paul ringo george
first john
second paul
rest ringo george

But if you use these modifiers you can save a lot of dodgy text work:

@echo off
echo %~n1
echo %~p1
echo %~x1

which will give you (assuming the file actually exists):

c:\>test.cmd c:\Users\Ringo\BeatlesSongs.txt


You can get some more parameters by typing FOR /? or CALL /? at the command line