0

I have been searching for a way to rename 150 files daily simply by executing 1 command. The current files are in the same folder C:\reports. The file names differ and the only change I have to make is replace yesterday's date and replace it with today's date except on Monday, replace Friday's date to Monday. Example - File 1 - Batch030315.xlsx File 2 - Input030315.xlsx

Tomorrow, the file name would be Batch030415.xlsx & Input030415.xlsx.

Any help anyone can offer would be greatly appreciated.

Thanks

2
  • 1
    150 files seem to be enough to deserve their own folder. Why not just put the files in a folder and copy that folder each day using the current date as the new folder name? This will be far simpler to manage IMHO.
    – krowe
    Commented Mar 4, 2015 at 2:26
  • How about if the program ran Mon-Fri and changed the date of every file to the current date?
    – barlop
    Commented Mar 4, 2015 at 4:30

1 Answer 1

0

You are not very specific as to what patterns exist and what rules to follow. Regardless, my JREN.BAT hybrid JScript/batch utility should be able to easily and quickly meet your needs. JREN.BAT renames files via regular expression replacement. It is pure script that runs natively on any Windows machine from XP onward.

I'll assume you want to rename all .xlsx files that have 6 digits immediately before the extension. If this is the case, then the old date doesn't really matter - you can simply rename all files that meet the pattern to use today's date:

@call jren "\d{6}(?=\.xlsx$)" "ts({fmt:'{mm}{dd}{yy}'})" /i /j

If there are files that meet the pattern, yet should not be renamed because they contain the wrong date, then you can simply supply the target old date as an argument and substitute it for the old 6 digit mask:

@call jren "%1(?=\.xlsx$)" "ts({fmt:'{mm}{dd}{yy}'})" /i /j

If the above script were named fixDate.bat, then you would use fixDate 030315 from the command line.

If you want to compute the old date, then you can throw in my getTimestamp.bat hybrid utility and use the following batch script.

@echo off
setlocal
call getTimestamp /f "{w}" /r dayOfWeek
set "offset=-1"
if %dayOfWeek% equ 1 then set "offset=-3"
call getTimestamp /od %offset% /f "{mm}{dd}{yy}" /r oldDay
call jren "%oldDay%(?=\.xlsx$)" "ts({fmt:'{mm}{dd}{yy}'})" /i /j

No matter what your exact requirements, you should be able to use these two utilities to meet your needs. Both utilities are extremely flexible with many options. Help can be obtained from the command line using:

jren /?

getTimestamp /?

You might want to pipe the help through MORE so you can read each line before it scrolls off the screen. I have my console configured to have a large buffer so I can scroll to see prior lines of output, so I don't need MORE.

jren /? | more

getTimestamp /? | more

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .