Hi, Phil and Exiftool community.
I'm using Exiftool for Windows to reorder a personal photo archive of several hundred thousand photos.
Now all the photos are in the folders of the following structure:
ROOT FOTO Year Country City [Place] [Event]
For example:
C:\foto\2016\italy\rome\piazza Venezia\concert
C:\foto\2016\france\nice\la Place Massena
Many folders have national symbols in the title, for example:
C:\FOTO\2016\Россия\Москва\Красная площадь
I want to assign the folder names (except FOTO and year) to a variable to write each of them to one or more tags. Such as keywords, titles, and so forth.
How can this be done so that the first pass is to assign variables that are the same for all files in the folder, and then the second pass to process all several hundred files in the folder?
I understand that I must to make a parsing path in config file, but I have problems with the unfamiliar Perl language, and there may be problems related to the presence of spaces and national symbols in the folders name.
Assigning the folders names to Keywords can be done in a single command. First, you have to strip away everything before the year, then you can do a substitution on the slashes (internally, exiftool treats Windows backslashes in a path as slashes) and use the -sep option.
Assuming you wish to preserve previously existing keywords:
exiftool -sep "##" "-keywords+<${directory;s(^.*foto/\d{4}/)()i;s(/)(##)g}" -r C:\FOTO
This command will make sure each folder name under the year will be entered as a separate keyword. It will recurse through all subdirectories and split the directory path properly for each file.
Spaces won't be a problem with this command, but you may want to do some testing with regards to Cyrillic characters. My quick test here shows that it should copy ok, but displaying it through cmd might require that you check out FAQ 10 (https://exiftool.org/faq.html#Q10) and FAQ 18 (https://exiftool.org/faq.html#Q18).
Copying the folders to a different tag would be slightly different. You wouldn't require the -sep option, but you would have to decide how you want each folder separated from the others and if you're going to overwrite the tag or add this data in some way.
Assuming the use of a CommaSpace as the separator and you want to overwrite the old tag:
exiftool "-Title<${directory;s(^.*foto/\d{4}/)()i;s(/)(, )g}" -r C:\FOTO
If instead of overwriting the old tag, you want to append to the end of it:
exiftool "-Title<$Title ${directory;s(^.*foto/\d{4}/)()i;s(/)(, )g}" -r C:\FOTO
Hi StarGeek.
Many thanks for the detailed and immediate answer.
These constructions I tried before I wrote to the forum. Right after I read practically the entire forum.
This only works if I explicitly specify the entire path from C: to the desired folder in a command line. Entire path can be long and I have to work as the typist. At the same time I shouldn't be mistaken. It is difficult and inconvenient.
I also think it's not efficient to make parsing for every file, because they're about 200, 000. The folders are only about one thousand.
But the most important that the received list of values requires to be used the different purposes:
- the complete list for keyword tags;
- the first item on the list for the following tags: XMP:XMP-dc:Description, EXIF:IFD0:ImageDescription and IPTC:Caption-Abstract;
- the second element on the list for the following tag: EXIF:IFD0:XPSubject;
- the last element on the list for the following tags: EXIF:IFD0:XPTitle and XMP:XMP-dc:Title.
(It promotes the most exact display of information in Synology PhotoStation)
Therefore I think that not to do without use of config file. Besides I need to use the existing modules from the time_zone.config and convert_regions.config files.
Quote from: VlCTOR on September 13, 2017, 08:46:16 PM
This only works if I explicitly specify the entire path from C: to the desired folder in a command line. Entire path can be long and I have to work as the typist. At the same time I shouldn't be mistaken. It is difficult and inconvenient.
You can CD to the directory above "Foto" on what ever drive the images are on and use the dot
. as the current directory path. Or you can copy/paste the drive path by selected the target folder, holding SHIFT+Right click, and selecting "Copy as Path". Or if you're using Windows 8 (not sure about earlier) or newer, you can type part of the path and hit tab to autocomplete to the next directory down. One way or another, you're going to need to get the path into the command line somehow. This is the same for all command line programs.
QuoteI also think it's not efficient to make parsing for every file, because they're about 200, 000. The folders are only about one thousand.
But it is going to have to parse and write every file anyway. The parsing part for something like this takes up only a fractional amount of the execution time. But if you run the command for each folder, that is going to take a long time. The largest performance hit with exiftool is the startup. By running it once for each folder, if you have 1,000 folders, you've increased that performance hit by x1000. See this thread (https://exiftool.org/forum/index.php?topic=1402.0) and Common Mistake 3 (https://exiftool.org/mistakes.html#M3).
QuoteBut the most important that the received list of values requires to be used the different purposes:
And all this can be placed in a single command which will insert all the info in one run. These are all very simple procedures. If it needs to be repeated, it can be placed in a .BAT file for later runs.
Quote from: StarGeek on September 14, 2017, 01:39:53 PM
You can CD to the directory above "Foto" ...
In this case, the command does not work correctly.
We're getting only "." (dot) in the keywords list.
PH Edit: Fixed improper quoting