Main Menu

Organize by Date

Started by Nickwell24, July 15, 2023, 05:12:11 PM

Previous topic - Next topic

Nickwell24

Hello everybody,

1st thing first, thank you Phil for making this great tool.

I've been pouring over the documentation, the forums, and talking to ChatGPT over the past 24 hours trying to get a script perfect.  I started using Windows, but that seemed to complicate thing, so now I'm running this on a Synology Server (Linux) and Macbook Air.

Here's what I'm trying to do:

exiftool -o -r "-FileName<%f%+c.%x" "-Directory<DateTimeOriginal" -d '%Y/%Y-%m/%Y-%m-%d/' .

From everything I've read, this script SHOULD:
- recursively scan for all the files within the existing directory.
- The files maintain their same name unless there's a conflict, in which case it'll add a _#.
- The Directory structure will be generated based on the Capture Date in the year/year-month/year-month-day format.
- The files will be copies from the original location.
- The Destination and Source Directory are both the present working directory.

Also, from what I understand from the literature, if a file doesn't have a DatetimeOriginal, then it'll remain untouched.  If I want to add an additional arguement, I can add it to the left of the script, as the tool looks at the furtherst right arguement first.

My question is this:
1) Does this script look correct?
2) Is there a better way of doing it?
3) I'm confused on how the tags works:

I've included both Directory and Filename for this example.  From my understanding, the Directory means it'll create the Directory where it's being moved based on the DateTimeOriginal value, and the FileName tells the file how to be named in the new location.  Does that mean if the file doesn't contain a DateTimeOriginal, then it won't be moved and I should add an additional -Directory>ModifiedTime to the left so there's essentially a catch-all so the file is moved either based on the Date Taken or the date when it was modified last?  This is where my head is confused.

Nickwell24

#1
For those who come across this post later. I want to provide an update after more trial & error.

Original Script:
exiftool -o -r "-FileName<%f%+c.%x" "-Directory<DateTimeOriginal" -d '%Y/%Y-%m/%Y-%m-%d/' .

Issue #1: -o needs an argument behind it.  Because I'm specifying a location at the end ".", whatever location I put after -o will be ignored, so . will suffice.

Update #1:
exiftool -o . -r "-FileName<%f%+c.%x" "-Directory<DateTimeOriginal" -d '%Y/%Y-%m/%Y-%m-%d/' .

Issue #2: I believe, this script will actually only make the Directories, as it's the furthest argument that has no errors. Meaning -FileName essentially is ignored.  I can fix this by simply removing it and making the Directories with the -d (Date) format argument.

1) Remove Directory and build that into FileName

exiftool -o. -r "-FileName<DateTimeOriginal" -d /%Y/%Y-%m/%Y-%m-%d/%%f%%+c.%e .

The other benefit of this route. The counter ensures that no files are left behind.



To anybody who this has helped. I STRONGLY encourage you to build a Directory of photos that are copies.  Had I not created a "testing area", then I'd have cause myself some issues.  Also, use TestName in place of FileName, until you're seeing the output you want.

Phil Harvey

Quote from: Nickwell24 on July 16, 2023, 11:02:28 PMexiftool -o . -r "-FileName<%f%+c.%x" "-Directory<DateTimeOriginal" -d '%Y/%Y-%m/%Y-%m-%d/' . .

This didn't write FileName due to common mistake 5c (you need to use = instead of <).  Also, I think you mean %e instead of %x.

- 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: Nickwell24 on July 15, 2023, 05:12:11 PMIf I want to add an additional arguement, I can add it to the left of the script, as the tool looks at the furtherst right arguement first.

Technically, each additional attempt to write the same tag, in this case it would be Filename, overrides the previous assignment.  But the result is the same, writing to the same tag name will use that last viable option.

QuoteI've included both Directory and Filename for this example.  From my understanding, the Directory means it'll create the Directory where it's being moved based on the DateTimeOriginal value, and the FileName tells the file how to be named in the new location.

My advice is don't.  You can include the directory path as part of writing to Filename.  Trying to write to both has a complicated interaction.  I wrote a break down in this StackOverflow answer for someone who was writing to both.


QuoteDoes that mean if the file doesn't contain a DateTimeOriginal, then it won't be moved

That is correct

Quoteand I should add an additional -Directory>ModifiedTime to the left so there's essentially a catch-all so the file is moved either based on the Date Taken or the date when it was modified last?

Copying from FileModifyDate is a reasonable if you want to make sure everything is moved. The direction of the arrow that you are using here is wrong and I don't believe there is a "ModifiedTime" tag.

I would suggest
exiftool -o . -r '-FileName<$DateTimeOriginal/%f%+c.%e' -d '%Y/%Y-%m/%Y-%m-%d' .

Personally, I don't like moving the %f and %e into the date string.  It's limiting and makes it more difficult to add other tags if desired, such as Make/Model if you have multiple cameras.

Because the tag copy now includes static text and % variables, a dollar sign is added to the front of the tag name.
* 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).