batch change date of all files in dir based on name order

1

I have a lot of images sorted according to their filenames: img1.jpg, img2.jpg ...

I need to change the file date which is now the same on all images so that img1.jpg date is before img2.jpg etc

I don't care what the start date is or what the time difference between 2 images is (1 sec will work). I need this because some services ie flickr rely on the image file datetime which I lost.

Any way to do this ?

kofifus

Posted 2018-10-14T03:00:11.070

Reputation: 179

Question was closed 2018-10-14T08:47:25.077

Please note that https://superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.

– DavidPostill – 2018-10-14T08:47:35.497

luckily I managed to get a great answer that will probably be useful to others before you put it on hold ... this kind of moderation is bs – kofifus – 2018-10-15T01:04:31.047

Hey, folks, I'll delete my answer if you really truly feel the questioner does not deserve it, but if he/she has any sense they will have copied it by now. – Michael Harvey – 2018-10-16T16:49:36.930

great answer, please keep it – kofifus – 2018-10-16T20:59:31.140

The essence of it is that copy /b filename+,, redates the file to the current time. – Michael Harvey – 2018-10-16T21:10:10.847

Answers

3

@echo off
echo Before:
for %%A in (*.jpg) do (
    for /f "tokens=1-2 delims=" %%i in ('"forfiles /m "%%A" /c "cmd /c echo @fdate @ftime" "') do echo %%i %%j %%A
)
echo Changing dates...
for %%A in (*.jpg) do (
    echo Redating %%A
    copy /b "%%A"+,, > nul
    ping -n 2 127.0.0.1>nul
    )
echo After:
for %%A in (*.jpg) do (
    for /f "tokens=1-2 delims=" %%i in ('"forfiles /m "%%A" /c "cmd /c echo @fdate @ftime" "') do echo %%i %%j %%A
)

Output:

Before:
22/12/2016 21:52:17  img01.jpg
15/04/2017 19:25:39  img02.jpg
26/12/2010 11:00:45  img03.jpg
03/02/2018 20:48:00  img04.jpg
15/07/2018 20:01:14  img05.jpg
29/03/2012 19:28:54  img06.JPG
04/10/2003 16:47:54  img07.jpg
04/08/2006 17:27:25  img08.jpg
Changing dates...
Redating img01.jpg
Redating img02.jpg
Redating img03.jpg
Redating img04.jpg
Redating img05.jpg
Redating img06.JPG
Redating img07.jpg
Redating img08.jpg
After:
14/10/2018 09:25:48  img01.jpg
14/10/2018 09:25:49  img02.jpg
14/10/2018 09:25:50  img03.jpg
14/10/2018 09:25:51  img04.jpg
14/10/2018 09:25:53  img05.jpg
14/10/2018 09:25:54  img06.JPG
14/10/2018 09:25:55  img07.jpg
14/10/2018 09:25:56  img08.jpg

Michael Harvey

Posted 2018-10-14T03:00:11.070

Reputation: 832