Computing.Net > Forums > Programming > Using Batch to Rename 'some' files

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Using Batch to Rename 'some' files

Reply to Message Icon

Original Message
Name: Dazman98
Date: October 22, 2007 at 22:15:25 Pacific
Subject: Using Batch to Rename 'some' files
OS: Win2003/Batch
CPU/Ram: Quad/4Gb
Model/Manufacturer: Dell
Comment:

We pull down files via FTP, these files are in hex format with no extension (eg. 008C334D) and the company that hosts the FTP site has said they can not change these files to have a different filename.

Our internal systems are set to look for files in a local directory starting with W.*
I have found some code that will allow me to put 'W.' at the start of every file so our system will see it and pick it up. (eg. W.008C334D)

Code to do this:
for %%i in (*.*) do (ren "%%i" "W.%%i")

Note: Once our system has picked up this file (W.008C334D) and processes it, the file is renamed to X.* (eg. X.008C334D)

What I would like to do is write some code that says if a file already exists with W.* do not rename it, else I will get W.W.008C334D and so on

As I am not too familiar with batch files and if/else loops, could you please assist me by writing some code to that will only rename file that do NOT start with W.

Thanks for your help in advance
Darren


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: October 23, 2007 at 01:41:26 Pacific
Reply: (edit)

Just replace your For with the following

for %%i in (*.) do (ren "%%i" "W.%%i")


Report Offensive Follow Up For Removal

Response Number 2
Name: Dazman98
Date: October 23, 2007 at 02:29:52 Pacific
Reply: (edit)

Something so simple can be so beautiful

Thanks a lot IVO


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: October 23, 2007 at 03:44:09 Pacific
Reply: (edit)

I wouldn't use the dot; but it's your funeral.

================================
for /f "tokens=* delims= " %%a in ('dir/b/a-d ^|find /v "W" ^|find /v "X"') do (
ren %%a W%%a


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 4
Name: IVO
Date: October 23, 2007 at 04:06:33 Pacific
Reply: (edit)

Please M2, may you explain why my tip is perceived so harmful? I tested it and it ignores directories that have usually no suffixes, not to say the statement acts on a specific, well monitored folder.


Report Offensive Follow Up For Removal

Response Number 5
Name: Dazman98
Date: October 23, 2007 at 05:10:04 Pacific
Reply: (edit)

M2
Are you able to explain the logic behind that code as I dont really understand what it is happing in it
Thanks


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: October 23, 2007 at 06:06:40 Pacific
Reply: (edit)

Hi IVO,

Nothing wrong with your code. Just seems odd to have a one char filename with an eight char extension.

Dazman98,

It acts on all files which have NEITHER W NOR X in the name.



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software