user2899671
user2899671

Reputation: 11

Change extension of selected files with CMD

I have a folder with well over 400 RAR, ZIP and 7Z files. I want to make a bat file that change the extensions of selected files in this folder as follows, RAR->CBR, ZIP->CBZ and 7Z->CB7 without renaming files not selected.

I have tried with:

ren %1 *.cbr

and:

ren %~n1.rar *cbr

but it does not work.

The bat file is going to be placed in the Send To menu.

I want, if possible, to use only cmd, as I don't know any scripting, or programming language.

Thanks

Upvotes: 1

Views: 1735

Answers (1)

Thomas W
Thomas W

Reputation: 14164

[This answered your original question, which as more about "all" or multiple files.]

You can use the FOR loop. Type for /? for details.

First, try the FOR command out to make it ECHO (print) the filename. You can use this to test what you want/think it's going to do:

for %f in (*.rar) do echo %f

Then, to actually rename, you'll need something like:

for %f in (*.rar) do ren %f *.cbr

[Following your edit]:

If you're calling a batch file from 'Send To' or whatever, your select file should come in in parameter %1 (and %2, %3 etc if multiple). You may also be able to use %* for all parameters.

Try echoing it somewhere, to console or a file, to test whether you're receiving these & what's happening. Save the following as a batch file, and try it:

echo %1
pause

In a batch file, % symbols need to be doubled up (for parsing reasons). So to rename, you might try something like:

for %%f in (%*) do echo %%f
for %%f in (%*) do ren %%f *.cbr

See also: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

Upvotes: 1

Related Questions