News:

2023-08-10 - ExifTool version 12.65 released

Main Menu

Dynamic file renaming

Started by Alyssa, April 15, 2017, 03:12:51 PM

Previous topic - Next topic

Alyssa

Hello

I've been using for quite a while now a script to rename image files based on their create date...

The script is the following(.bat file in Windows machine)
exiftool -d "%%Y_%%m_%%d Ore %%H_%%M_%%S%%%%-c.%%%%e" "-filename<file:filecreatedate" -P .

Which returns a filename like:
YYYY_MM_DD Ore HH_MM_SS

Now, I recently recovered an old photo collection where I used to add the suffix"(E)",for edited images(also usually kept the original ones), so I was wondering if it's possible to tweak the script in a way that it keeps certain tags within the file name if these are present(like (E) or (T) or other types),while renaming the rest of the file name, in a way that looks like this:

(T)YYYY_MM_DD Ore HH_MM_SS

(Assuming any tag at all is within the filename)

Thanks for any advice in advance  :-*

Phil Harvey

Sure this is possible, but I need to know how the suffix is separated from the rest of the file name.  A few examples would be useful too.

- 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 ($).

Alyssa

All suffixes are inside round brackets and they're usually 1-2 letters long.

For example

Image Name(T)

Or

Image Name(T)(E)

to name a couple

Phil Harvey

OK, try this:

exiftool -d "%%Y_%%m_%%d Ore %%H_%%M_%%S" "-filename<${filename;$_ = /(\(.*\))/ ? $1 : ''}${file:filecreatedate}%%-c.%%e" -P .

I also moved the filename format codes out of the date format string to make things a bit easier to understand.

- 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 ($).

Alyssa

Works wonders, thank you very much  ;D

Alyssa

#5
Sorry, another thing...I tried to make a suffix variant of the script by switching the {file:filecreatedate} part before the filename<${filename;$_ = /(\(.*\))/ ? $1 part but it kind of not working, how can I make a suffix version(at the end of the file name instead of at the beginning) of the script?

Edit:Never mind that, after many trials & erros I got it working

Suffix version:
C:\exiftool.exe   -d "%%Y_%%m_%%d Ore %%H_%%M_%%S%%%%-c" "-filename<${file:filecreatedate}${filename;$_ = /(\(.*\))/ ? $1 : ''}.%%e" -P .


Phil Harvey

Your command looks OK to me.  You could have kept the %-c out of the date format code, but this shouldn't change anything:

exiftool -d "%%Y_%%m_%%d Ore %%H_%%M_%%S" "-filename<${file:filecreatedate}%%-c${filename;$_ = /(\(.*\))/ ? $1 : ''}.%%e" -P .

- 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 ($).