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!

Dos command

Status
Not open for further replies.
Jun 8, 2010
6
CA
Hello,

Not sure if this is the correct forum - I am trying to use a rename function in DOS/XP to rename a file from

ShippingConfirmation_20100702114533.txt

to

Completed.20100702114533.txt

These commands do not five me the correct output

ShippingConfirmation_* Completed*.txt

ShippingConfirmation_* Completed*


What would be the correct command to get the desired output?

Thanks
 
You are going to have to use a BAT file:

Code:
@ECHO OFF
REM Create a list of files want to rename, and store them in a file
dir  shippingconfirmation_*.* /b > filelist.inf

REM Loop through the file, and rename 
for /F "tokens=1,2 delims=_" %%A IN (filelist.inf) do rename %%A_%%B Completed.%%B

REM Delete file that contained files to be renamed. 
del filelist.inf

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hey Thanks! That worked...Until of course the client changed their mind and wanted the date and time separated by an _ as well

ShippingConfirmation_20100702_114533.txt

This has to become

Completed.20100702_114533.txt

How would I make that change?

Cheers,
 
That's going to be close to impossible to do, because there's no way to tell where the date ends and the other numbers begin.

If you really need to do this you're going to have to do it using a VB script instead of a DOS command batch file.

VB offers much better string manipulation, and will make separating the date part from the rest of the number much easier.

forum329



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Code:
FOR /F "usebackq tokens=1,* delims=_" %%A IN (`DIR /B *.txt`) DO REN %%A_%%B Completed.%%B
 
Does it have to be a DOS / Batch file? You get get Windows apps that do the same functionality with knobs on.

I uses one at home but for the life of me can't remeber what it's called.

Guess a search for File Renamer Freeware*

*check the license conditions for commercial useage.

Robert Wilensky:
We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top