I only want the code to work on CSV or txt files say.
I'm not sure how to get the files own date. BUT... I definitely need the time as well.
I need the time because when moving to the other location, if not renamed, there is a chance there will be an existing file with the same name.
I already have some code to add the system current date to a file - but am not sure how to adapt and instead get the files own date and time.
The code I have is:
Code: Select all
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "stamp=%DD%%MM%%YYYY%.%HH%%Min%"
:loop
ren "%~1" "%~n1.%stamp%%~x1"
shift
if not "%~1"=="" goto :loop
EDIT: I also need to check that a file hasn't already been renamed and has the correct format date and time added to the end. I'm lost with this one - how will I do string checking using DOS commands?
Any help to start me off would be great
Thanks
OM