2

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 ?

5
  • Please note that 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
    Oct 14 '18 at 8:47
  • 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
    Oct 15 '18 at 1:04
  • 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. Oct 16 '18 at 16:49
  • great answer, please keep it
    – kofifus
    Oct 16 '18 at 20:59
  • The essence of it is that copy /b filename+,, redates the file to the current time. Oct 16 '18 at 21:10
4
@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

Not the answer you're looking for? Browse other questions tagged or ask your own question.