News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Modify File Info

Started by iastate, August 05, 2020, 02:03:35 PM

Previous topic - Next topic

iastate

I'm new here so apologize in advance if this is a duplicate but I haven't been able to find my answer search the forum thus far.  I have a QNAP NAS where I have a bunch of different folders that have sub-folders and pictures in all the different folders.  I am trying to organize all my photos and wanted to go to a Year - Month - Day folder structure.  The first step in doing this is I wanted to make sure all the files match the METADATA for when they were taken (not just when they might have been copied onto the NAS).  Once the date / time stamp matches the metadata I want to rename the files from IMG_9214.jpg to something like 20090125_001.jpg for a picture taken on 01/25/2009.  From there I am looking to move them into the appropriate folder structure.

Not sure how much of this EXIFTool can handle but thought I would throw it out there and get your take since this program has been highly recommended by all.

Thanks in advance!

Travis

StarGeek

Take a look at the many examples found on the Writing "FileName" and "Directory" tags page and the Renaming Examples on the main doc page.  The main option for doing this sort of thing is the -d (dateFormat) option and some of the format codes detailed in the -w (textout) option.

Your basic command would be something like this
exiftool "-Testname<DateTimeOriginal" -d "%Y%m%d%%+3.c.%%e" /path/to/files/

This command will rename files based upon the DateTimeOriginal tag embedded in the file.  The -d option reformats  that timestamp into the filename pattern you gave. 

The definitions for the various date codes (%Y, %m, %d) can be found here.  The %c and %e codes definitions are from the -w option.  The percent signs for these need to be doubled because they are in the Date format string. 

The %c is a copy number.  The leading plus sign indicates that a leading underscore is to be added.  The 3 indicates the number is to be padded to a length of 3.  The dot indicates that the copy number is to be always included.  Normally if there isn't a file with the same name, the copy number won't be used.

The %e is the file extension.

This command is using Testname so you can test the command and see what the results would be without actually changing any filenames.  Change it to Filename to actually run the command.

You don't mention what OS you'll be running on.  Normally, if the command is being run from a Mac/Linux, you'd want to swap Double/Single quotes.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

StarGeek beat me to it.  The only thing thing I might mention is that I think you want %%+.3c instead of %%+3.c

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

iastate

Do all the files have to be in the same directory or can it search my NAS for all image files in the thousands of different folders I have them in today?

Phil Harvey

Specify the the top-level directory and use the -r option to get ExifTool to recurse into all subdirectories.

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

iastate

Thanks StarGeek & Phil!  I will play around with these suggestions.

iastate

That worked great and super easy to use after playing around a little testing it out.  One more question - is there a command with this tool that allows you to move the files to folders based on file date?  I am looking to sort by highest level folder year - then month - then date (i.e. 2020 top level then under that January thru December folders then 1 - 31 folders for a 3 level structure)

StarGeek

#7
You can insert the directory path as part of the date string.  For example
exiftool "-Filename<DateTimeOriginal" -d "/path/to/new/%Y/%m/%d/%Y%m%d%%+.3c.%%e" /path/to/files/

Would end up with something like
/path/to/new/2020/08/06/20200806_001.jpg
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

iastate

I tested this out and it worked partially....it moved them to the right folder but changed the file name to include the JPG at the end instead of keeping it as a file extension of .JPG.


Phil Harvey

There should be a "." before the "%%e".

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

StarGeek

Doh!  I keep messing those up.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

iastate

You have been super helpful here!  Thanks!!!

one last question - am I able to do the same things with .MOV files or is there a tweak to the command for different file types?

StarGeek

Quote from: iastate on August 07, 2020, 12:58:42 PM
one last question - am I able to do the same things with .MOV files or is there a tweak to the command for different file types?

Maybe.

You would most likely use CreateDate instead of DateTimeOriginal but there's a problem with video files.  According to the spec, the timestamps in video files are supposed to be in UTC.  But not all cameras follow that, mostly non camera phone ones, because they often don't know the time zone.  So the timestamps may or may not be off by the time zone you're in.  Run this command to see all the time related tags in the file
exiftool -G1 -a -s -Time:all /path/to/file/

If you can determine that the timestamps are not set to UTC, then you can use the previous commands with only the tag name changed.  If they are set to UTC, then you can add -api QuickTimeUTC to the command.  The hard one is when the timestamp is set to UTC and the video was shot in a different time zone than the one you are currently in and that may require some manual adjustments.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

iastate

Right on!  That worked.  I do have one more question - is there a way to move all files into a single folder before doing my conversion?  I have many folders and sub folders that different files left in them after doing the process described above and I am curious if I can run a command that says take any file left in any folder (under the main folder) and move it to the main folder level.

Is this doable?

Phil Harvey

exiftool "-directory=DSTDIR" -r SRCDIR
...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 ($).

iastate

I am geting "Warning: Error creating directory for..." and no files move.  DSTDIR I used the destination directory and SRCDIR as the Source Directory.  I have tried using the destination directory as one already created and also one that was not created already with the same result. 

It ends up scanning 755 directories - updating zero files and 3696  files weren't updated due to errors.

Phil Harvey

Yes, DSTDIR is the destination directory.  The error indicates that DSTDIR couldn't be created.  What was the DSTDIR you used, and what was the current directory when you ran the command?

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

iastate

exiftool '-directory=/Volumes/Stuff/All\ Other\ Files' -r /Volumes/Stuff/PHOTOS\ NAS

This is the command I used.  I am running it off an external HDD where the top level folder is Stuff and the sub folder I want to put all other files into is call "All Other Files".  "PHOTOS NAS" is the sub folder that has many folders underneath it that is also under Stuff.

I am clicking and dragging the source and destination paths from Finder into Terminal to ensure I am getting the path right. 

StarGeek

Quote from: iastate on August 08, 2020, 01:23:42 PM
'-directory=/Volumes/Stuff/All\ Other\ Files'

I don't believe you need to escape the spaces when you have quotes around the argument.  Use either
-directory=/Volumes/Stuff/All\ Other\ Files
or 
'-directory=/Volumes/Stuff/All Other Files'
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

iastate

when I run this command:

exiftool -ext jpg '-Filename<DateTimeOriginal' -r -d '/Volumes/Photos Project/Pictures/%Y/%B/%Y-%m-%d%%+.3c.%%e' /Volumes/Photos\ Project/4TB_WD_BackupWorkLaptop

My objective is to rename the files it can to the date it was created and then move it to the appropriate year - month folders.  This appears to be working good for all images that have writeable tags.  The issue I am having now is I am getting an error "Warning: Error removing old file...." and it copies the file to the new folder structure with a new name but it also leaves the old image and old name in the old folder.  This is causing me headaches because I am trying to move the ones it can (and rename) while leaving only the ones it cant rename so I can go in manually and tag / rename them. 

Any thoughts?