rename files with wildcard

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
eponcede
Posts: 1
Joined: 25 Oct 2012 12:56

rename files with wildcard

#1 Post by eponcede » 25 Oct 2012 13:03

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!!!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: rename files with wildcard

#2 Post by foxidrive » 25 Oct 2012 19:37

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?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: rename files with wildcard

#3 Post by abc0502 » 26 Oct 2012 05:35

Maybe he want the date of modification ?! :roll:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: rename files with wildcard

#4 Post by foxidrive » 26 Oct 2012 05:57

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.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: rename files with wildcard

#5 Post by abc0502 » 26 Oct 2012 06:00

:lol: That's right :lol:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: rename files with wildcard

#6 Post by abc0502 » 27 Oct 2012 00:49

@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.

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.

Post Reply