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