Bath file running via context menu

July 11, 2010 at 19:33:46
Specs: Windows XP
I create invoices via excel and theyre named "FirstName LastName AmoutBilled.xls" and I wanted to add the word "PAID" at the end of the filename. I could do this by just renaming the file manually, but it is a bit too slow when doing a lot of them (and the person who does this isnt very computer savvy), so instead I created a conext action for the .xls file type so when you right click an .xls file there is a PAID action in the menu, and it is linked to the batch file.

Thats not the issue, the issue is to get the batch file to work properly.

So. Looking around I saw a solution at: and I changed the solution to: FOR /f "tokens=* delims=" %%a in ('dir/b/a-d') do (ren "%%a" "%%~Na PAID%%~Xa") and that worked great, it added PAID to the end of the filename.

However, the issue is that it's changing ALL .xls files within the same directory (due to the 'dir/b/a-d' part I guess), and I only want the file(s) I select to change. Is there a way to obmit the dir part?

For example if I have just a simple REN *.xls PAID.xls in the batch file, it changes just the file I have selected, but obviously doesnt change it the way I want it to with keeping the original file name and adding PAID to the end of the file.

So is there way to get the FOR /f "tokens=* delims=" %%a in ('dir/b/a-d') do (ren "%%a" "%%~Na PAID%%~Xa") code to work with just one file? Or an alternate code?


See More: Bath file running via context menu

Report •

July 13, 2010 at 07:31:27
I think you need to have double quotes (") surrounding
%1 in the context action and the following command in
the batch file:

ren %1 "%~n1 PAID%~x1"

Report •

July 15, 2010 at 11:39:51
Thank you, that works perfectly, and a lot less complicated!
I could have sworn I tried something like that before.. but it didnt work.

By the way double quotes or not, they both work :)

Report •

Related Solutions

Ask Question