Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming files in a batch process

Status
Not open for further replies.

SQLWilts

Programmer
Feb 12, 2001
651
GB
Has anyone done this... I am just kicking ideas around and any input would be appreciated:

I have a number of files that are produced by a batch process every night. There will be > 15 of them, but I do not know exactly how many there will be.

Their names are like:

mycomapny-name.xml.1
mycompany-name.xml.2
mycompany-name.xml.22

etc etc

I need to get to:
mycompany-name1.xml
mycompany-name2.xml
mycompany-name22.xml

I am looking at using something like forfiles or similar. There is no windows scripting host or perl etc on the server - installing these is not an option.

Good old command line batch processing only guys/gals.

Not as straight forward as it looks - any input gratefully received.
 
Some of these should get you close
thread779-1584252
thread779-1567132
thread779-1541192
thread779-1523201
thread779-1515548
thread779-1387129
 
smah,
Thanks for your reply.
After some thought (and a walk away for a while) I imitated a "Do/While" loop like this:

Code:
REM get count of files
FOR /F %%j in ('dir *.xml.* /A-D-H /B ^| find /C /V ""') DO SET COUNTER=%%j

REM Loop until the count = 0
:loopstart

REN mycompany-name.xml.%COUNTER% mycompany-name%COUNTER%.xml 

SET /a COUNTER=%COUNTER%-1

IF NOT %COUNTER% EQU 0 GOTO LOOPSTART

:LOOPEND

I will have a look at those posts though to see if there is a better way.

Thanks for looking and posting though
 
Based on your example data, I would use the "." as the token delimiter, then simply rename by rearranging the tokens.

Code:
for /F "tokens=1,2,3 delims=." %%i in ('dir /b *.xml.*') do (
  ren %%i.%%j.%%k %%i%%k.%%j
  )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top