Files, Renaming in Batch Process

H

Hank in KC

I have several folders in which files are named: C-01-001.xxx, C-01-002.xxx,
C-01-003.xxx ... C-01-080.

I would like to rename the files as: C01-001.xxx, C01-002.xxx, C01-003.xxx,
etc. In other words simply remove the dash following the first character C.

I've gone to the command prompt and entered:

a) Rename C-01-*.* C01-*.8 with the resulting name C01--001.*,
C01--002.*, etc. In fact getting another
dash.

b) Rename C-01-* C01* with the result C-01-001

c) Rename C-01* C01* with the result C011-001


It appears I need to eliminate one of the characters in the file name.

Any suggestions?
 
S

Stan Brown

I have several folders in which files are named: C-01-001.xxx, C-01-002.xxx,
C-01-003.xxx ... C-01-080.

I would like to rename the files as: C01-001.xxx, C01-002.xxx, C01-003.xxx,
etc. In other words simply remove the dash following the first character C.


Batch file RR.BAT:

@setlocal
@set X=%1
@set Y=%X:C-=C%
ren %X% %Y%
@endlocal

In the "set Y" command, I use an obscurely documented feature of
environment variable substitution. That works only for named
environment variables, not for batch parameters.



Then use the FOR command to call the batch file:

FOR %Z in (C-*) do call RR %Z

I've tested the batch file, but not the FOR command, so check the
syntax carefully.



You might be able to do the whole thing in a FOR command, but it
would be easier to get wrong and harder to test.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top