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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file to rename files

Status
Not open for further replies.

Maturi

IS-IT--Management
Oct 9, 2003
81
GB
Hi

In the old days (pre-Windows ME) the operating system did not allow spaces in the filename. Now with XP, spaces are allowed. So whereas before I would have a file called - 'MyDataFile.doc' now I can call it 'My Data File.doc'

I used to use a Dos batch file to rename (or copy) lots of files with the simple command line

'RENAME MyDataFile.Doc NewDataFile.doc' etc.

And when you run this in a Dos window the files would be renamed.

The trouble is I can't use this approach if there are spaces in the files name beacuse the Dos command line rejects

'RENAME My Data File.Doc New Data File.doc'

Does anyone have an alternative way to rename lots of files either in a batch file or using Explorer or some other utility ??

Thanks
 
Try putting the filenames in quotes, example is below:

RENAME "My Data File.Doc" "New Data File.doc"

--------------------------------------------------------------------------
"Who is General Failure and what is he doing on my computer?"
--------------------------------------------------------------------------
 
As Laddy said, anything you enclose in quotes "xx yyy zzzz" will be treated as a whole string, therefore will correctly rename your files. This is the same for typing paths in dos
Code:
cd c:\program files
wont work
Code:
"cd c:\program files"
will

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Just to clarify, you have to put the command outside of the quotes and only the long directory/file name goes in the quotes. eg:

cd "Program files"

--------------------------------------------------------------------------
"Who is General Failure and what is he doing on my computer?"
--------------------------------------------------------------------------
 
yeah, lol, sorry. including the cd inside the quotes would parse no command and just enter the whole thing as a single string that has no meaning.

Copy Paste error. Ma' Bad!

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Thanks to all

Seems so obvious!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top