Renaming files by adding the time difference

Started by Thiru, March 12, 2023, 06:08:06 AM

Previous topic - Next topic

Thiru

Hi,

I would like to rename files according to the date, time and taking account of the time difference of where I live and where the photos was taken.
I have already renamed some of the files without taking account of the time difference. (This problem has arised because I forgot to change the date and time on the camera).
Files are named in this format
YYYYMMDD_HHMMSS_DSC_nnnn
I would like to add 4hrs30mins to HHMMSS
i.e This file
20170813_105106_DSC_2810  needs to be changed  20170813_152106_DSC_2810
Can it be done in exiftool?

Thank you
Thiru

Phil Harvey

Hi Thiru,

What I would do is a 3 step process:

1. Set the file system modify date from the file name:

exiftool "-filemodifydate<filename" DIR

2. Correct the date:

exiftool "-filemodifydate+=4:30" DIR

3. Set the filename from the new date:

exiftool "-testname<${filemodifydate}%.15f.%e" -d "%Y%m%d_%H%M%S" DIR

The last command ignores the first 15 characters of the file name and adds the new date.  Here I'm writing TestName so you can test to be sure things are working the way you want before you actually rename the files because this action is not reversible.  It is a dangerous command because it will mess up the names of any files which don't conform to this naming scheme.  Change "testname" to "filename" to actually do the renaming.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Thiru

Hi Phil,
Thanks a lot. It worked.
Firs I did did not see any visible changes after typing the first two commands.
Third command produced the results what I wanted.
Thanks again for the tool and giving the solution to my problem.

With kind regards
Thiru

Phil Harvey

Hi Thiru,

Glad it worked.

The first 2 commands only change the filesystem file modification date, and not the file itself.  They were necessary because the 3rd command uses the modification date to set the file name.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Thiru

Sorry Phil
I should have asked this as well.
If the file names are in this form DSC_nnnn.JPG, how do I add YYYYMMDD_HHMMSS_ as a prefix  and adding 4hrs30mins to HHMMSS
I thought I can handle it by modifying the third command and so typed the first command and resulted in getting warning messages and stopped proceeding to the second and third command.

Before posting my first message I had already changed some of the files from  DSC_nnnn.JPG to YYYYMMDD_HHMMSS_DSC_nnnn.JPG without taking account of the time difference.

Sorry to trouble you
Many thanks
Thiru

Phil Harvey

I was considering doing this from the start.  Here is a command to take the last 8 characters of the file name instead of ignoring the first 15:

exiftool "-testname<${filemodifydate}_%-8f.%e" -d "%Y%m%d_%H%M%S" DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Thiru

Thank you Phil. I changed testname to filename and it worked.
Much appreciated.
Thiru