Win .BAT file Move & Rename Using File Modified Date - Not Run Date

Stephen Marsh

Well-known member
I’m not sure if what I wish to do is possible, I have spent a lot of time searching without much luck.

I’m looking for a Windows native command line to use in a simple .bat or .cmd file that is available to many different Windows OS. I don’t want any third party software dependencies that require installation (for example I could do this with ExifTool).

What I have found so far is:

move "C:\Source\*.csv" "C:\Destination\Prefix_%Date:~-10,2%_%Date:~-7,2%_%Date:~-4,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%.csv"

So, we have a source folder which may contain one or more .csv files. These are moved to a destination folder and renamed using the date and time when the script is run. The results may be:

my-input_file.csv (modified 31/03/2015 at ‏‎19:48:12)

Is moved and renamed to (Prefix_DD_MM_YYYY_HH_MM_SS.csv):

Prefix_25_04_2017_19_45_55.csv (the date and time when the .bat is run)

Two issues:

1) I don’t want the date/time when the script is run – I want the date/time modified of the file.

2) This only works one at a time for a single file in the source folder, I would like all/multiple .csv source files to be moved and renamed to the destination folder. This second point is not a show stopper, there should only be one .csv file in the source folder anyway, however I would like to make this bullet proof if possible.

I’m sure that this is relatively easy for those in the know, so I’m looking forward to finding out what the secret is!

Stephen Marsh
Last edited:

Stephen Marsh

Well-known member
Thank you for the reply Tim! I can’t get that command to work, however that could be user error.

As is always the case, the expectation is that it should be easy to simply swap out the run date of the batch file to use the file modified date, however it does not appear to be that easy!

I would certainly appreciate further help if it can be provided.

If this is not possible directly via a .bat/.cmd file, the I would of course be happy to use another native OS method, such as using a .bat file to run Powershell or VBscript etc… I would just need more details, this is beyond my abilities and is stretching what I can achieve via web searches.

Stephen Marsh


Well-known member
Hello Stephen,

From the forums I saw, every one said VB Script was the way. I'll let you know what .BATman comes up with.

Stephen Marsh

Well-known member
Thanks Tim, I would like to use a “lowest common denominator” for disparate Windows desktop and sever OS versions, keeping this as simple as possible. I was hoping for a single self contained .bat or .cmd file, however if the script has to reference another bit of code saved somewhere then so be it. The file modified or created date is an intrinsic part of the file or file system, I would have thought that this would be easy to do (spoken like a true layman!).

Stephen Marsh

e-Book: Steps to a More Profitable Workflow

smartsoft cover
Key Steps To Making Your Workflow Profitable
The most profitable print shops remain agile and respond to their customers’ demands while keeping inventory levels at a minimum, decreasing the amount of time from order to delivery and making it easy to do business with. Read the Post