elegant way of capturing SourceFile as a TAG

Started by arc12, May 05, 2019, 09:39:19 AM

Previous topic - Next topic

arc12

I am looking at a process whereby a large number of images from a series of collections are tagged with information about their origin. The origin (essentially a locator into an archive) is expected to consist of:
a) a collection identifier. This can just be the directory name, and I have a Windows BAT file which takes drag/drop folders and can add this to a TAG of my choice (Comment in the example below)
b) the file path WITHIN the collection. This naturally comes out of exiftool as SourceFile, but I cannot see an elegant way of setting a TAG of my choice with this value

My current command for (a) is (I do want to remove the sub-directory structure, so that all metadata-augmented images in the collection appear in a single output directory):
exiftool.exe -r -comment="%~n1" %1 -o "OUT/%~n1/"

I can see how (b) could be done with writing out a CSV and renaming columns (FileName becomes SourceFile and SourceFile becomes NewTag) then writing that back to the files in OUT/
But that is not elegant! Neither is writing a batch file which iterates over the originals

Is there an elegant solution?

Cheers, Adam

StarGeek

Take a look at the FileName, Directory, and FilePath tags from the Extra Tags pageDirectory will be the directory path based upon what was entered on the command line.  So if you enter a relative path (such as a dot for the current directory), that's what the result will be.  FilePath will always be the full, absolute file path and name.

Example output
C:\>exiftool -Filename -Directory -Filepath y:\!temp\Test4.jpg
File Name                       : Test4.jpg
Directory                       : y:/!temp
File Path                       : y:/!temp/Test4.jpg

C:\>cd /d Y:\!temp\

Y:\!temp>exiftool -Filename -Directory -Filepath Test4.jpg
File Name                       : Test4.jpg
Directory                       : .
File Path                       : Y:\!temp\Test4.jpg


One thing I would suggest is using some other tag other than Comment to hold important data.  That tag is very fragile, as many image processing programs will overwrite it with the name of the program. 
* 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).

arc12

@StarGeek - thanks for the reply.
I was just showing the example with Comment to simplify the example. My intention is to use an XMP custom prefix/tag.

To clarify my question (b): what I want to do is to copy the relative path to the file into a named tag (will be a custom prefix/tag). "Relative" here is in relation to the starting directory supplied to exiftool. Also, I want to handle a large number of files using the "-r" capability of exiftool.

Starting with:
exiftool.exe -r "-comment<$Directory" %1 -o "OUT/%~n1/%%f%%c.%%e"

I've tried various ways of using ${Directory;s/%1//} to trim Directory down, according to what is in %1 (changed \ to // and space to \s)... but it all goes horribly wrong.
I think I'll have to resort to a brute force scripted loop.

It is so frustrating that this doesnt work:
exiftool.exe -r "-comment<$SourceFile" %1 -o "OUT/%~n1/%%f%%c.%%e"

Cheers, Adam

Phil Harvey

Hi Adam,

Maybe something like this would do what you want:

1)  cd %1

2)  exiftool -r "-comment<directory" * -o "OUT/%~n1/%%f%%c.%%e"

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

arc12

Phil -
thanks, you've unlocked things! Easy when you know how.

I ended up with:
cd %1
%~dp0exiftool.exe -k -r "-comment<$Directory/$FileName" * -o "../OUT/%~n1/%%f%%c.%%e"

I can now drop a folder on the "bat" file, with exiftool in the same directory and nicely preserve the subdirectory-path/filename in the original folder = my de-facto identifier in the archive collection.

Now, on to next steps.

Many thanks for creating and maintaining exiftool.

Cheers, Adam