Move exisitng folder name (structure) into image "tag"

Started by jappie, September 12, 2013, 07:33:43 AM

Previous topic - Next topic

jappie

Hello,

I have a folder structure for my images whereby the folder name (and structure) is an indication of the tags I would like to retrieve the images by in a new structure that is %Y/%m/%d based. I have no problems to create this new structure but my question is if it is possible to somehow "move" the names of the exisiting folders into the image "tags"

an example:
image located in family/holiday/corsica_2007 --> will go to 2007/07/15/2007-07-05_10:25:34.jpg. I would like this image to have the tags "family", "holiday" and "corsica_2007" associated with the file.

Any ideas, tips or tricks?

Thanks a lot for your help.

Cheers JP

Phil Harvey

Hi JP,

Sure.  See this post for someone else who did the same thing.  (The forum search feature is your friend.)

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

jappie

Hi Phil.

Have to say; you are fast! Thanks for pointing me to the right thread I thought I'd seen them all, but alas.
I've got it working with the config file and would like to "add" to "subject" instead of "keywords" so changed:

  • "-keywords<dirtree" to
  • "-subject<dirtree"

This works fine but it overwrites any existing tags that may already exist.
Questions:
- is there any way of "adding to" instead of "overwriting" for this option?
- how can I eliminate the leading folder (.) that is included in this tag as the first keyword?

Any help much appreciated, cheers JP

Phil Harvey

Quote from: jappie on September 12, 2013, 10:08:20 AM
- is there any way of "adding to" instead of "overwriting" for this option?

Yes:  "-subject+<dirtree"

Quote- how can I eliminate the leading folder (.) that is included in this tag as the first keyword?

Type "*" instead of "." on the command line.  Either that, or the conversion could be modified to add this line:

shift @parts if @parts and $parts[0] eq '.';

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

jappie

Hi Phil,

This is growing on me and I'm getting closer yet also start to feel (a bit) lost...
Now when I run the command the terminal feedback in any cases is: "Warning: Shift value for XMP-pdf: Subject is not a number - <filename>"

For these files the subject is then not added and the tag is instead added to "Keywords".

Logical for some maybe but I might be missing something here.

BTW: the command I run is the following:
exiftool -config config_tags "-subject+<dirtree" * -r -P -d '%%e/%Y/%m/%d-%m-%Y/%d-%m-%Y_%H.%M.%S' '-filename<${CreateDate;}-(%f)%-c.%e' '-filename<${DateTimeOriginal}_${Make;}_${Model;}-(%f)%-c.%e'

whereby " config_tags" contains the instructions as per the link you directed me to...
As a final observation I note that some files with for instance .png or .tiff extensions are not following the "%e" switch and do not contain CreateDate, thus throwing other errors. This is not a major problem but I'd like to set up a fully comprehensive script for my needs.

Any insights here?

Cheers JP

Phil Harvey

Quote from: jappie on September 12, 2013, 11:30:07 AM
Now when I run the command the terminal feedback in any cases is: "Warning: Shift value for XMP-pdf: Subject is not a number - <filename>"

Specify xmp-dc:subject instead of just subject to avoid warnings when trying to set other tags.

QuoteFor these files the subject is then not added and the tag is instead added to "Keywords".

No.  You're fooling yourself somehow here.  XMP-dc:Subject will still be written properly, and Keywords will not be written unless you specify "Keywords" in the command.

QuoteAs a final observation I note that some files with for instance .png or .tiff extensions are not following the "%e" switch and do not contain CreateDate, thus throwing other errors. This is not a major problem but I'd like to set up a fully comprehensive script for my needs.

You need to decide how to name files without a CreateDate or DateTimeOriginal.  Then just assign a default '-filename=some_default-(%f)%-c.%e' before attempting to copy the filename from CreateDate and DateTimeOriginal.

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

jappie

Hi Phil,

it's proving to be more difficult than I anticipated but am very willing to learn.
My preferred default file name structure would be "%d-%m-%Y_%H.%M.%S%-c.%e"

Then how do I pass this default to the line as a "default"? Right now I get results like this: "-%m-%Y_%H.%M.%S-9" and on top, the desired hierarchical structure (/YY/MM/DD-MM-YYYY) is not created.

Quoteexiftool -config config_tags "-xmp-dc:subject+<dirtree" * -r -P -d '%%e/%Y/%m/%d-%m-%Y/' '-filename=%d-%m-%Y_%H.%M.%S%-c.%e' '-filename<${CreateDate;}%-c.%e' '-filename<${DateTimeOriginal}_${Make;}_${Model;}%-c.%e' -ext jpg

Thank you very much for your help already this far, I'm hoping you can give me the final push in the right direction.

Cheers JP

Phil Harvey

I'm confused.  How do you propose to fill in the year, etc for your default file name if there is no CreateDate or DateTimeOriginal?

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

jappie

It must be me that is confused and is thus creating confusion;

in the instructions (or an example I found somewhere) I found a reference to the ';' as a means of creating different naming "schemes".
I am under the impression that the code I posted previously uses a sort of "hierarchy" of proposed naming schemes, like :

1. '-filename=%d-%m-%Y_%H.%M.%S%-c.%e' is the default, yet if there is a CreateDate then use
2. '-filename<${CreateDate;}%-c.%e' and if there is also a make and model to be retrieved use,
3. '-filename<${DateTimeOriginal}_${Make;}_${Model;}%-c.%e'

So to answer your question (and this is where your coaching style brings the boomerang back), I now see how the 1st statement is also dependent on the presence of either a CreateDate or DateTimeOriginal... So, if I understand correctly the first statement should make no reference to EXIF data as they might not be present. Good.

Will that also solve my problem with the directory structure no longer being respected?

Cheers JP

Phil Harvey

I'm glad things are starting to make a bit of sense now.

Quote from: jappie on September 12, 2013, 05:36:02 PM
Will that also solve my problem with the directory structure no longer being respected?

yes, provided your default file name has the structure you want.

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

jappie

Hi Phil,

I turns out that one of my problems was that I wanted to use different -d formats for the directory structure and the file name. I found another thread where you explain and advice to do this in two steps. Works a dream now so that's great. Thank you for your great tool and fabulous support!

One last comment; I noticed that the images taken with my Nexus smartphone throws warning "Invalid EXIF text encoding" yet the file gets renamed according to the desired output. Thought you might want to know.

For other readers of this forum here is the list of commands I have used

1. To create a new folder structure (/extension/Model/YYYY/MM/DD-MM-YYYY) whilst moving the existing folder structure names into tags  I used:
#Pass 1a: move files with EXIF into the proper directory:
exiftool -config config_tags '-xmp-dc:subject+<dirtree' '-Directory<%e/${MyModel}/$DateTimeOriginal' -d '%Y/%m/%d-%m-%Y' -r *

Note: this is dependent on the configuration script attached to this post.

1b. move files with no EXIF:
#Pass 1b: move files with no EXIF:
exiftool -r '-directory</Imagearchive/NOEXIF' *


2.  rename the files (with EXIF) to include references to Make and Model
#Pass 2: rename the files (with EXIF):
exiftool -config config_tags -r -d '%d-%m-%Y_%H.%M.%S' '-filename<photo;_(%f)%-c.%e' '-filename<${CreateDate;}%-c.%e' '-filename<${DateTimeOriginal}_${Make;}_${Model;}-(${MyFilenumber})%-c.%e' *


3. (Optional) | Reset the file date and time to the date taken

#Pass 3: reset file dates to date created
exiftool "filemodifydate<datetimeoriginal" *


Open a beer and enjoy the fruits of your work!


Phil Harvey

Excellent!  I'm glad you got things working the way you wanted.

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

effgee

Hi there jappie and Phil,

jappie, your set of commands does almost everything I was looking for, thank you!

I am having a weird problem that I just can't figure it out.

On Pass 1a, it says, move files with EXIF into the proper directory:

On my system (Ubuntu Linux), it doesn't move them, it copies them. Can someone explain why? I would like them to move.

Phil Harvey

Can you give the exact command you are using that copies the files?  Also, are you moving them to a different filesystem, or just another directory within the same filesystem?

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

brightwolf

I am trying to copy this trick to automatically set Keywords in my photo files based on folder structure.

My structure looks like this:
Album
-- Holiday
-- -- 2010 Paris France
-- -- 2011 Montpellier France

The photos are only in the last folders of the tree. I would like the photos in "2010 Paris France" folder to get these keywords: Album, Holiday, 2010, Paris, France

So basically split the folder tree based on '/' as in config_tags, but also split the folder name based on ' '.

How does this work? All help appreciated.
Photographer. Hobbyist. Using iMac to manage photos, with Photo Mechanic Plus, Pixelmator, Luminar, and exiftool. Longing back to Aperture sometimes.