rename file by using date/time/maker/model/directory information

Started by djtn, June 01, 2013, 09:45:34 AM

Previous topic - Next topic

djtn

Hi,

I want to rename my files in a way that they contain the EXIF creation date/time, the folder name the file is stored with a sequence number and the EXIF camera maker/model info. If the creation date/time is not unique, it would be great to get the file serialized. In addition, a renaming of all possible JPEG-file extentions (I have jpg/JPEG/JPG) should take place into jpg.

Example:
the image files I want to get renamed is:
c:\mypics\2012\birthday\myfile1.JPG
c:\mypics\2012\birthday\myfile2.JPEG

After renaming it should look like this:
20130601_155901_birthday001_Canon_5D.jpg
20130601_155901_birthday002_Canon_5D.jpg

If the timestamp is not unique, the sequence number should just go up by one, no further order needed

I have no clue how to do that in its full scope.I managed to get the EXIF date time but did not manage to combine it with the other information I mentioned.

exiftool -P -"Filename<DateTimeOriginal" -d %Y%m%d_%H%M%S.jpg 1.jpg

any help is highly appreciated

Phil Harvey

To use other tags in the file name, use this format:

exiftool -"Filename<${DateTimeOriginal}_${SOMETAG}_${ANOTHERTAG}.jpg" -d %Y%m%d_%H%M%S FILE

The details of the format string are explained in the -p option documentation.

- Phil

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

djtn

thx, Phil. The link seems to be invalid, could you please check ?

djtn

yes I FTFM  8)

all I strugle with is getting the directory name accordingly. With that command, $directory returns an ".", which says current directory in DOS terms. In my case, I want to have "mypics" returned.

exiftool -"Filename<${DateTimeOriginal}_${directory}_${Make}_${Model}.jpg" -d %Y%m%d_%H%M%S%%-c -r -ext jpg c:\mypics
returns: 20121208_183347_._SAMSUNG_GT-N7000.jpg
desired: 20121208_183347_mypics_SAMSUNG_GT-N7000.jpg

Any hint how to do that ?

Phil Harvey

In your command you specify "c:\mypics" for the directory, so that should be the base Directory reported by ExifTool.

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

ryerman

Quote from: djtn on June 01, 2013, 12:16:50 PM
yes I FTFM  8)

all I strugle with is getting the directory name accordingly. With that command, $directory returns an ".", which says current directory in DOS terms. In my case, I want to have "mypics" returned.

exiftool -"Filename<${DateTimeOriginal}_${directory}_${Make}_${Model}.jpg" -d %Y%m%d_%H%M%S%%-c -r -ext jpg c:\mypics
returns: 20121208_183347_._SAMSUNG_GT-N7000.jpg
desired: 20121208_183347_mypics_SAMSUNG_GT-N7000.jpg

Any hint how to do that ?
Using Exiftool, -directory returns the complete path, including the drive letter, colon and forward slash.
Windows does not allow the colon and forward slash in a file name.
To use only the name of the folder which contains a file, you can parse the directory path.
The Advanced Formatting feature can be used, as described in the documentation for the -p option. (see link above)


In your command replace ${directory} with ${directory;s/.+\///} and see what happens.

Jim
Windows 10 Home 64 bit, Exiftool v12.61

djtn

Quote from: ryerman on June 01, 2013, 10:58:13 PM

Using Exiftool, -directory returns the complete path, including the drive letter, colon and forward slash.
Windows does not allow the colon and forward slash in a file name.
To use only the name of the folder which contains a file, you can parse the directory path.
The Advanced Formatting feature can be used, as described in the documentation for the -p option. (see link above)


In your command replace ${directory} with ${directory;s/.+\///} and see what happens.

Jim

This doesn't make a change on my Windows 7 system. It still returns a '.' while running on files in c:\mypics or in any other directory.
I found a circumvention by assigning the Folder Name manually to the ${XPComment} Tag. For further reference I then use the following command to rename my files:
exiftool -"Filename<${DateTimeOriginal}_${XPComment}_${Make}_${Model}.jpg" -d %Y%m%d_%H%M%S%%-c -r c:\mypics\

Phil Harvey

I really don't understand why it would be a '.'.  Using the -p option you can see what ExifTool wants to name the files (but note that the "%c" will not be converted because this is done when the FileName is written):

exiftool -p "${DateTimeOriginal}_${directory;s/.+\///}_${Make}_${Model}.jpg" -d %Y%m%d_%H%M%S%%-c -r -ext jpg c:\mypics

What is the output of this command for one of your files?

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

djtn

Quote from: Phil Harvey on June 03, 2013, 07:12:22 AM
I really don't understand why it would be a '.'.  Using the -p option you can see what ExifTool wants to name the files (but note that the "%c" will not be converted because this is done when the FileName is written):

exiftool -p "${DateTimeOriginal}_${directory;s/.+\///}_${Make}_${Model}.jpg" -d %Y%m%d_%H%M%S%%-c -r -ext jpg c:\mypics

What is the output of this command for one of your files?

- Phil

Phil, the output looks good if I let it run on c:\mypics\1994
20121208_183347%-c_1994_SAMSUNG_GT-N7000.jpg
if I do the rename, the file looks now as it should:
20121208_183347_1994_SAMSUNG_GT-N7000

Thanks for your help.

The problem was

Phil Harvey

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

djtn

Quote from: Phil Harvey on June 03, 2013, 02:41:46 PM
Quote from: djtn on June 03, 2013, 12:27:52 PM
The problem was

... ?

- Phil

The '.' stands for current directory in terms of DOS/Windows Filesystem terminology. So, when running exiftool from the same directory where my single test image file resides in, exiftools returns '.' instead of the name of the directory the file is in.

c:\Program Files (x86)\Bildbearbeitung>exiftool -"Filename<${DateTimeOriginal}_${directory;s/.+\///}_${Make}_${Model}.jpg" -d %Y%m%d_%H%M%S%%-c 1.jpg"
returns 20121208_183347_._SAMSUNG_GT-N7000

When specifying the full path to the test file the problem disappears and returns the correct name of the directory the file is stored into:
20121208_183347_bildbearbeitung_SAMSUNG_GT-N7000.jpg

Phil Harvey

Thanks.

This is what I suspected, and was trying to communicate, but apparently my communication skills aren't very good.

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

djtn

There's one point left...
I decided to use exiftool for setting the XPComment information to the name of the directory the file resides in. My command looks like this:
c:\Program Files (x86)\Bildbearbeitung>exiftool -XPComment=${directory;s/.+\///} -r c:\mypics\2002

the comments field of the files in the c:\mypics\2002 directory then look like:  ${directory;s/.+\///}  and not 2002 like I wanted it to be. Any idea what to change?

Phil Harvey

You should be using "<" for copying tag values, not "=".  Also, you'll need to put the argument in quotes because of the "<".

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

djtn

Quote from: Phil Harvey on June 04, 2013, 06:31:51 PM
You should be using "<" for copying tag values, not "=".  Also, you'll need to put the argument in quotes because of the "<".

- Phil

I did:
c:\Program Files (x86)\Bildbearbeitung>exiftool -P -"XPComment<${directory;s/.+\///}" -r -ext jpg c:\mypics
and got the expected directory named as XPComment tag.

Phil, thanks for you help and advise.