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

batch rename files

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
US
I have dozens of directories with hundreds of files. In each directory the files are automatically named file1, file2, file3 etc... I need to copy the files and prepend the directory name so I can dump all the files in one directory. For example, if I have a directory named May and files inside may called file1, file2, file3 etc.. I want to copy to a directory called 2003 and inside I want the files to be named may_file1, may_file2, etc.. so I will eventually have a whole years worth of files in one directory - may_file1, june_file1, july_file1 etc...

I thought it would be simple enough in DOS but its been a long time since I had to do anything with xcopy or copy.

Can anyone tell me an easy way? or does anyone have a vbscript that might do the same thing..

any suggestions would be appreciated...

 
Try

For %a in (*.*) do if not exist may_%a ren %a may_%a

This will catch out any files that already exist called may_
Change the prefix for each month as appropriate.

John
 
thanks, that would have been perfect, except they seem to have named the files with spaces and - imbedded so I need to figure out if I can somehow quote the long file names, DOS chokes on the spaces or the dashes...

 
I managed to find a VB script that would do what I needed, but Id still like to find a simple Command Line that could handle the long file names...

thanks again
 
Slight alteration, should work but not completely sure:

For "%a" in (*.*) do if not exist "may_%a" ren "%a" "may_%a"

John

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top