Click here to Skip to main content
15,877,384 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

I need to rename a lot of files and need to do it in a batch file.

The file names differ and I need to "pad" the files with a 0 in front of the file names.
I don't know the First thing about scripts :confused:
I'm already using a batch file to copy files then i need to add a 0 in front. that is all I want to do.
Batch File:
XCOPY Z:\*.* D:\CClas\CCLASFML\Reports\Certificate /D:01-26-2010 /C
XCOPY Y:\*.* D:\CClas\CCLASFML\Reports\STT /D:01-26-2010 /C

The process must be automated, and the server does'nt have Powershell :(

This is what i'm looking for:
for %i in (*.*) do ren %i 0%i
but when i use it dos tells me :
i was unexpected at this time.
Got It!
The Correct Code is:
for %%N in (*.*) do ren "%%N" "0%%N"

Thanks EveryOne
Updated 26-Jan-10 20:13pm

Why don't you use a script?
Share this answer
This is not really an answer to your question, but rather an alternative solution, but I think it's worth mentioning. Have you tried Total Commander's Multi Rename Tool (Ctrl+M)?
If you are automating something this won't help, but if you just need to copy/rename something from time to time - it's worth a try. Just a thought :)
Share this answer
Something like:
for %i in (*.*) do ren %i 0%i
Share this answer
If you want you can windows power shell:

cd "c:\New Folder (2)"
get-childitem -Path *.* | rename-item -NewName {"0" + $}
Share this answer
A biterscripting script.

# Script Rename0.txt
var str folder, list, file, newname
lf -n "*" $folder ($ftype=="f") > $list
while ($list <> "")
    lex "1" $list > $file ; stex -p "^/^l[" $file > $newname
    set $newname = "0"+$newname    # "pad" the files with a 0 in front of the file names
    system rename ("\""+$file+"\"") ("\""+$newname+"\"")

Run the script with

script Rename0.txt folder("C:/somefolder")

Will rename all files in C:/somefolder by padding a zero ("0") in front of the file name. For help page for stex (string extractor) command -
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900