Author Topic: Creating Directories  (Read 993 times)

irinaonline

  • Full Member
  • ***
  • Posts: 30
Creating Directories
« on: June 16, 2017, 11:52:16 PM »
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

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2432
Re: Creating Directories
« Reply #1 on: June 17, 2017, 01:21:12 AM »
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.
Code: [Select]
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
Quote
The ";" 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
« Last Edit: February 24, 2019, 12:56:33 PM by StarGeek »
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14597
    • ExifTool Home Page
Re: Creating Directories
« Reply #2 on: June 17, 2017, 07:20:45 AM »
A Shortcut can also work in conjunction with the -sep option.

Very smart!

Quote
Couldn'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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).