ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: pheon on June 06, 2021, 12:06:23 PM

Title: Move files into nested directories, by year then by model
Post by: pheon on June 06, 2021, 12:06:23 PM
I want to organize my families photos by year and then camera model using something like

exiftool -r -d %Y "-directory<CreateDate/model" .

So the file structure would be 2014/Canon, 2014/Nikon etc where Canon and Nikon are subdirectories under 2014.

I do this now in two separate steps. Is it possible to combine them?
Title: Re: Move files into nested directories, by year then by model
Post by: Phil Harvey on June 06, 2021, 07:41:16 PM
The command would be:

exiftool -r -d %Y "-directory<$CreateDate/${model;}" .

The empty advanced formatting expression for Model causes illegal characters to be removed from the directory name.

But it probably isn't smart to have the command recurse into the directory you are creating, so I would suggest moving them to a different parent directory by running the command from another directory.

- Phil
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 23, 2021, 07:28:15 PM
Hello Phil -

Thank you so much for writing this amazing tool. I came across your amazing tool just recently and still in the learning/newbie mode.

Can you please guide me in accomplishing the following:

- Organize images from a folder called '2021' into sub-folders MONTH / DATE / CAMERA MODEL ?

Also, do I need to specify the source path and/or destination path? Or can I copy the tool into the 2021 folder and run it from there?

Thank you in advance for your help!!

- Sajeed
Title: Re: Move files into nested directories, by year then by model
Post by: Phil Harvey on September 23, 2021, 09:42:31 PM
Hi Sajeed,

A command could be:

exiftool -r -d %m/%Y-%m-%d "-directory<DSTDIR/$CreateDate/${model;}" SRCDIR

Where SRCDIR is the directory containing the images, and DSTDIR is the directory for the month directories to go into.

- Phil
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 24, 2021, 12:31:14 PM
Hi Phil -

Thank you so much for your prompt reply and the sample command.

Is there a way to create the month directory spelled out instead of 01? For example: 01 - January

Thanks again for your help and this amazing software.

Best,

Sajeed
Title: Re: Move files into nested directories, by year then by model
Post by: StarGeek on September 24, 2021, 01:04:06 PM
See Common Date Format Codes (https://exiftool.org/filename.html#codes) for the list.  To include the month name, you would use %B.  Also, you'll need to add quotes because of the spaces.

-d "%m - %B/%Y-%m-%d"
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 20, 2022, 05:27:56 PM
Hi Phil -

Thanks once again for creating such an amazing tool. It's been working great.

I have a question regarding photos that are processed through an app to erase background and then uploaded to the folder. I tried .PNG format and .JPG format, in both cases, the images are not picked up by the exiftool. If I upload the photos straight from the phone's camera without removing their background, they're processed by the exiftool and separated by year/month/date and camera model.

I also noticed that the photos which I processed via the app doesn't have much meta info, does have the date information. Is there a way I can still have the exiftool process those images as well and separate them into subdirectories by year/ month / date?
Title: Re: Move files into nested directories, by year then by model
Post by: StarGeek on September 20, 2022, 07:39:28 PM
It sounds like the app you're using is removing the needed tags.  Exiftool can't sort them with your command if the data isn't there.

Your best bet is to copy the data from the originals into the processed files.  Then you should be able to use exiftool to move them  The command would be something like
exiftool -TagsFromFile /path/to/originals/%f.%e -All:All /path/to/processed/
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 22, 2022, 10:19:42 PM
I tweaked my code like this:

exiftool -r -d "%Y/%m - %B/%d - %a" "-directory<filemodifydate" "-directory<createdate" "-directory<datetimeoriginal" "-directory<C:\Pictures\Camera Roll/$CreateDate/${model;}" "C:\Pictures\Camera Roll"

All my photos get auto copied to the C:\Pictures\Camera Roll folder. My exiftool.exe is stored in the downloads folder.

When exiftool runs, I want the photos to be sorted/organized in the following structure

C:\Pictures\Camera Roll
- 2022
-- 09 - September
--- Thu 22
---- SM-G981U
----- and the photos taken on that day with that particular device are moved into the respective folder.

For some reason after I added "-directory<filemodifydate" "-directory<createdate" "-directory<datetimeoriginal" upon executing exiftool, it's deleting my photos instead of organizing them.

I really appreciate the help and guidance.
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 22, 2022, 11:28:36 PM
COrrection - Only PNG files are getting deleted. I ran the code in command prompt to get the output and noticed this error when PNG files were remaining in the folder:

Warning: [minor] Tag 'CreateDate' not defined - C:/Pictures/Camera Roll/PR-20220920_134239.png
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 23, 2022, 12:26:34 AM
Quick update - I noticed that it's doing with JPG's as well. These 4 files were processed from the App to remove background and make edits and then uploaded to the folder.

Warning: [minor] Tag 'CreateDate' not defined - C:/Pictures/Camera Roll/2022/20220922_124148 (1).png
Warning: [minor] Tag 'CreateDate' not defined - C:Pictures/Camera Roll/2022/20220922_124156 (1).png
Warning: [minor] Tag 'CreateDate' not defined - C:/Pictures/Camera Roll/2022/PR-20220922_225845_1.jpg
Warning: [minor] Tag 'CreateDate' not defined - C:/Pictures/Camera Roll/2022/PR-20220922_225845_13.jpg

Any help on fixing this will be really appreciated.
Title: Re: Move files into nested directories, by year then by model
Post by: Phil Harvey on September 23, 2022, 01:25:27 PM
ExifTool will never delete a file.

I don't know what you want help with.  Your other app is deleting the metadata that you are trying to use.

- Phil
Title: Re: Move files into nested directories, by year then by model
Post by: StarGeek on September 23, 2022, 03:17:31 PM
Quote from: sajeed on September 22, 2022, 11:28:36 PMCOrrection - Only PNG files are getting deleted.

As Phil says, exiftool is not deleting them.  They're probably ending up in an unexpected directory.

PNG files rarely have any metadata to begin with unless you manually add it.  Use the command in FAQ #3 (https://exiftool.org/faq.html#Q3) to verify what data is actually in the file.
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 24, 2022, 12:30:42 AM
Hello StarGeek & Phil -

Phil - You are right, when I process the images through the App, it's deleting the Meta Data. And I was trying to understand how to add the data back to the file.

StarGeek - I kept searching on the forum and read lots of other posts of other users and their examples and came up with this, which seems to be working in my test environment. However I am trying to figure out how to add the -p preserve switch to preserve the FileModiyDate and also trying to see if exiftool can only scan the current directory and not the sub-directories, because I have so many nested sub-categories and I don't want to scan all sub-directories everytime the script is executed.

Please let me know if I am using too many extras in the code.

exiftool.exe -overwrite_original_in_place -if "not $CreateDate" "-CreateDate<FileModifyDate" -execute -overwrite_original_in_place -if "not ${model;}" "-model=Cleaned" -execute -r -d "%Y/%m - %B/%d - %a" -common_args "-directory<C:\Users\Administrator\desktop\test/$CreateDate/${model;}" "C:\Users\Administrator\desktop\Test"

During my test, I copied 50 images out of which 10 were copied from the App so they were missing the $CreateDate and $Model info. When exiftool ran, it ignored the 40 images and updated the 10 with Model Info and Populated the $CreateDate from the FileModifyDate, however at the end, it still showed Updated 40 files.

Then when I ran the script again, it didn't make any changes to the 10 images because the if statement worked as expected, however it still showed 40 files updated. I don't know what is being updated in the 40 files? That's why I thought of applying the preserve switch and somehow prevent it from scanning the sub-directories.

Once again, thank you so much for your help.
Title: Re: Move files into nested directories, by year then by model
Post by: StarGeek on September 24, 2022, 10:39:47 AM
Quote from: sajeed on September 24, 2022, 12:30:42 AMHowever I am trying to figure out how to add the -p preserve switch to preserve the FileModiyDate

Make sure you're using the -P (-preserve) option (https://exiftool.org/exiftool_pod.html#P--preserve) (uppercase P) and not the -p (-printFormat) option (https://exiftool.org/exiftool_pod.html#p-FMTFILE-or-STR--printFormat) (lowercase p).  They do different things.  All you need to do is add -P or -preserve.

Quotealso trying to see if exiftool can only scan the current directory and not the sub-directories

Exiftool will not process sub-directories unless you add the -r (-recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse).

QuotePlease let me know if I am using too many extras in the code.

Don't over complicate things. It's easier to run three separate commands instead of trying to merge them with the -execute option (https://exiftool.org/exiftool_pod.html#execute-NUM).  Take time to learn about how things work before using the more advanced options.  And using -execute in this situation won't save you any measurable time.

Quoteexiftool.exe -overwrite_original_in_place -if "not $CreateDate" "-CreateDate<FileModifyDate" -execute -overwrite_original_in_place -if "not ${model;}" "-model=Cleaned" -execute -r -d "%Y/%m - %B/%d - %a" -common_args "-directory<C:\Users\Administrator\desktop\test/$CreateDate/${model;}" "C:\Users\Administrator\desktop\Test"

I would use this
exiftool-overwrite_original -P -if "not $CreateDate" "-CreateDate<FileModifyDate" "C:\Users\Administrator\desktop\Test"

exiftool-overwrite_original -P -if "not ${model;}" "-model=Cleaned" "C:\Users\Administrator\desktop\Test"

exiftool-overwrite_original -P -d "%Y/%m - %B/%d - %a" "-directory<C:\Users\Administrator\desktop\test/$CreateDate/${model;}" "C:\Users\Administrator\desktop\Test"



The way you had it set up, putting the Directory assignment after the -Common_Args option (https://exiftool.org/exiftool_pod.html#common_args), would cause exiftool to try and make copies of each filed edited, though it would probably fail because the -d (-dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) was on the wrong side of the -Common_Args option.  From under Notes on the Writing "FileName" and "Directory" tags (https://exiftool.org/filename.html) page
     Writing the FileName and/or Directory tags alone causes the file to be renamed or moved, not copied. However, if any "real" tags are written at the same time, then the file is rewritten to the new destination and the original file is left unchanged

Also, you don't want to run -overwrite_original_in_place option (https://exiftool.org/exiftool_pod.html#overwrite_original_in_place), unless the files have ADS (https://en.wikipedia.org/wiki/NTFS#Alternate_data_stream_(ADS)).  Which they almost certainly won't unless you added them.  The main use for -overwrite_original_in_place would be on a Mac to preserve the MacOS specific file tags.

QuoteThen when I ran the script again, it didn't make any changes to the 10 images because the if statement worked as expected, however it still showed 40 files updated. I don't know what is being updated in the 40 files?

No idea.  It doesn't look like anything should change on a second run but I haven't tested it.

Since you appear to be using Windows, be aware that you do have to make changes depending upon if you're using PowerShell or CMD.  The above commands are for CMD.  In Powershell, you want to swap single/double quotes.
Title: Re: Move files into nested directories, by year then by model
Post by: sajeed on September 24, 2022, 01:20:11 PM
Hello StarGeek -

Thank you so much for taking the time to guide and correct the code for me. I really appreciate it. I just tried the code separately and it showed the output correctly. I've attached the screenshot.

My only question is, is it okay to execute exiftool from another location or should exiftool.exe be in the same directory where all the photos are?

Once again, thank you so much for your help and guidance. I really appreciate it.

Best,

Sajeed
Title: Re: Move files into nested directories, by year then by model
Post by: StarGeek on September 24, 2022, 02:48:30 PM
Quote from: sajeed on September 24, 2022, 01:20:11 PMMy only question is, is it okay to execute exiftool from another location or should exiftool.exe be in the same directory where all the photos are?

Exiftool can be anywhere on the computer as long as it's location is in the PATH variable.  If you type
path
into the command line, it will list all the directories that the command line will look into when you run a program.  Exiftool can be in any of these directories, though not all are appropriate places to put it.

Two ways of making it easier to make sure exiftool is in the PATH is to install it with either Oliver Betz's Alternate exiftool build (https://oliverbetz.de/pages/Artikel/ExifTool-for-Windows), which includes an installer.  Or if you use Chocolatey, there is a Chocolatey install package (https://community.chocolatey.org/packages/exiftool).