Move files into nested directories, by year then by model

Started by pheon, June 06, 2021, 12:06:23 PM

Previous topic - Next topic

pheon

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?

Phil Harvey

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

sajeed

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

Phil Harvey

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

sajeed

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

StarGeek

See Common Date Format 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"
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

sajeed

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?

StarGeek

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/
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

sajeed

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.

sajeed

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

sajeed

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.

Phil Harvey

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
...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

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 to verify what data is actually in the file.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

sajeed

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.

StarGeek

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 (uppercase P) and not the -p (-printFormat) option (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.

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.  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, would cause exiftool to try and make copies of each filed edited, though it would probably fail because the -d (-dateFormat) option was on the wrong side of the -Common_Args option.  From under Notes on the Writing "FileName" and "Directory" tags 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, unless the files have 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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype