HI... I ve been trying to learn do write a batch for soemthing really easy but I am getting confused...
I have 5 differente files every day with the same format that want to rename
O-10 Daily Operations Report 2012-10-24.xlsx
O-3 Enterprise Trading report Daily 2012-10-25.xlsx
and need to rename them to a differente format and add the date YYYY-MM-DD at the end... So basically
if (file contains O-3) rename to O-003 Enterprise Trading Report Daily YYYY-MM-DD.xlsx
and
if (file contains O-10) rename to O-003 O-010 Daily Operations Report YYYY-MM-DD.xlsx
so at the end my files will end up like:
O-003 Enterprise Trading Report Daily YYYY-MM-DD.xlsx
O-010 Daily Operations Report YYYY-MM-DD.xlsx
How can I do this...
PLEASE HELP!!!
rename files with wildcard
Moderator: DosItHelp
Re: rename files with wildcard
eponcede wrote:HI... I ve been trying to learn do write a batch for soemthing really easy but I am getting confused...
I have 5 differente files every day with the same format that want to rename
O-10 Daily Operations Report 2012-10-24.xlsx
O-3 Enterprise Trading report Daily 2012-10-25.xlsx
and need to rename them to a differente format and add the date YYYY-MM-DD at the end... So basically
They already have YYYY-MM-DD at the end. Can you clarify the original filename format?
Re: rename files with wildcard
Maybe he want the date of modification ?! 

Re: rename files with wildcard
eponcede wrote:so at the end my files will end up like:
O-003 Enterprise Trading Report Daily YYYY-MM-DD.xlsx
O-010 Daily Operations Report YYYY-MM-DD.xlsx
hehe Maybe he doesn't want a date at all. There's no date above.
Re: rename files with wildcard


Re: rename files with wildcard
@eponcede
This will rename files but won't do anything to the year-month-day part at the end,
I assumed it was a typing error, if it wasn't let us know.
If file name start with O-3 will be renamed to O-003 and the rest of the file name,
and if file name start with O-10 will be renamed to O-003 O-010 and the rest of the file name.
This will rename files but won't do anything to the year-month-day part at the end,
I assumed it was a typing error, if it wasn't let us know.
Code: Select all
@Echo Off
Setlocal EnableDelayedExpansion
For /F "delims=" %%A in ('DIR /B /A:-D "*.xlsx"') Do (
Set "Fname=%%A"
IF "!Fname:~0,3!" EQU "O-3" ( Ren "!Fname!" "O-003!Fname:~3!" )
IF "!Fname:~0,4!" EQU "O-10" ( Ren "!Fname!" "O-003 O-010!Fname:~4!" )
)
pause
If file name start with O-3 will be renamed to O-003 and the rest of the file name,
and if file name start with O-10 will be renamed to O-003 O-010 and the rest of the file name.