Main Menu

Creating Directories

Started by irinaonline, June 16, 2017, 11:52:16 PM

Previous topic - Next topic

irinaonline

If I want my directories based on following structure, how can I make sure, that empty fields in the processed files do not lead to a space at the end or to a double space in the string?

"-directory<${CountryCode;} ${Country;} ${State;} ${City;} ${Location;} ${SupplementalCategories;}"

The ";" is great but how can I further prevent a "." in the string?

Any help is highly appreciated, thank you!

StarGeek

#1
Try moving the addition of the space into the tag name with $_.=' '.  This isn't perfect, as there is still the possibility of a trailing space if the last variable doesn't exist.

"-directory<${CountryCode;$_.=' '}${Country;$_.=' '}${State;$_.=' '}${City;$_.=' '}${Location;$_.=' '}${SupplementalCategories;}"

A better option might be a user defined tag. Or maybe... *runs off to test*

A Shortcut can also work in conjunction with the -sep option.  Here's my test, using testname instead of directory, since I don't actually want to move my test file.  My test file has only four of your six tags defined.  Couldn't use simply "-testname<MyShortcut" as that only returned the last item in the shortcut.  I also had to include -m because if a tag didn't exists in this case, an error is thrown and it wouldn't process the file.  I didn't test using the Directory tag, so I don't know the situation there, but I assume it would be the same.
C:\>exiftool -CountryCode -Country -State -City -Location -SupplementalCategories "X:\!temp\aa\2015-03-31_0043.JPG"
Country                         : USA
State                           : California
City                            : Los Angeles
Supplemental Categories         : ENT

C:\>exiftool -sep " " -m "-testname<${MyShortcut;}" "X:\!temp\aa\2015-03-31_0043.JPG"
'X:/!temp/aa/2015-03-31_0043.JPG' --> 'X:/!temp/aa/USA California Los Angeles ENT'
    0 image files updated
    1 image files unchanged


The shortcut was defined simply as:
MyShortcut => ['CountryCode','Country','State','City','Location','SupplementalCategories'],
Just place it in the shortcut section of your .exiftool_config file (see example config if you don't already have a config file).

Whoops, almost missed this
QuoteThe ";" is great but how can I further prevent a "." in the string?
If you want to add a dot to the normal semicolon function, you'll have to actually put in what it does (see second paragraph of the Advanced Formatting docs), which is tr(/\\?*:|"<>\0)()d.  Your end expression would be
"-Directory<${MyShortcut;tr(\./\\?*:|"<>\0)()d}"

Edit: Long overdue edit.  Under Windows, the double quote in the tr function would have to be tripled, resulting in tr(/\\?*:|"""<>\0)()d
* 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

Quote from: StarGeek on June 17, 2017, 01:21:12 AM
A Shortcut can also work in conjunction with the -sep option.

Very smart!

QuoteCouldn't use simply "-testname<MyShortcut" as that only returned the last item in the shortcut.

Yes:

            8) With the redirection feature, copying a tag directly (ie.
            "'-DSTTAG<SRCTAG'") is not the same as interpolating its value
            inside a string (ie. "'-DSTTAG<$SRCTAG'") for list-type tags,
            shortcut tags, or tag names containing wildcards.  When copying
            directly, the values of each matching source tag are copied
            individually to the destination tag (as if they were separate
            assignments).  However, when interpolated inside a string, list
            items and the values of shortcut tags are concatenated (with a
            separator set by the -sep option), and wildcards are not allowed.


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