Click here to Skip to main content
14,640,725 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

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
Posted
Updated 26-Jan-10 20:13pm
v4
Rate this:
Please Sign up or sign in to vote.

Solution 1

Why don't you use a script?
:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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 :)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Something like:
for %i in (*.*) do ren %i 0%i
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

If you want you can windows power shell:

cd "c:\New Folder (2)"
get-childitem -Path *.* | rename-item -NewName {"0" + $_.name}
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

A biterscripting script.


# Script Rename0.txt
var str folder, list, file, newname
lf -n "*" $folder ($ftype=="f") > $list
while ($list <> "")
do
    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+"\"")
done



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 - http://www.biterscripting.com/helppages/stex.html
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100