Importing from CSV - matching partial filenames or wildcards

Started by benjamin, January 18, 2013, 12:48:07 AM

Previous topic - Next topic

benjamin

Hi There  :)

I hope to use exiftool to write metadata regularly to batches of images. The images may be different views of the same product, and would have metadata applied to all variations based on a common element in their filenames. For example, the images...

1532-245532_GREY_01_001.jpg
1532-245532_GREY_02_099.jpg
1532-245532_GREY_03_041.jpg
4563-992233_WHITE_01_220.jpg
4563-992233_WHITE_02_232.jpg
4563-992233_WHITE_03_240.jpg

For these files, consider the following ideal .csv to populate their metadata... (please excuse my hijacked fields)

SourceFile,CaptionWriter,Country,City
1532-245532_GREY*,GREY,SN1234,DJ99999
4563-992233_WHITE*,WHITE,SN3324,DJ92838

As you can see the filenames are not complete. I won't be able to determine the full filenames for the SourceFile values before generating the .csv and I'm hoping there is a way to match using  'contains' logic.
ie, if the filename contains the 'SourceFile' data, then match.

I saw a post which uses the 'if' feature, but I don't think this is necessarily the way to go...
https://exiftool.org/forum/index.php/topic,4544.0.html

Is there a way to do this in a one line execution of exiftool or am I going to have to script around this and call exiftool for each line in the .csv?
(it would be great to be able to use wildcards in the .csv...)

Thanks in advance :)

B

Phil Harvey

The -csv option isn't ideal for this because it requires an exact match with the name in the SourceFile column.  If you did this with the -@ option instead, you could take advantage of the shell globbing with an argfile like this:

1532-245532_GREY*
-CaptionWriter=GREY
-Country=SN1234
-City=DJ99999
-execute
4563-992233_WHITE*
-CaptionWriter=WHITE
-Country=SN3324
-City=DJ92838
-execute


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

benjamin

Hi Phil,

Damn. Thats a shame. Feature request? ;D

If I use an argfile, will exiftool be called individually for each argument?

ie - is there going to be a speedup if I use an argfile as opposed to calling exiftool for each line of csv from an external script?

Thanks again for the awesomeness that is Exiftool.

B



Phil Harvey

The -argfile option is the preferred method to improve performance.  ExifTool is called only once for the entire argfile.  Plus, you can keep the argfile open (with the -stay_open option) and keep adding arguments to it so that you can keep exiftool running if 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 ($).

benjamin

Hi Phil,

-stay_open is great. Thanks for pointing that out.

Unfortunately I can't seem to get the * wildcard to work in the argfile.

for a set of images in a folder called image.jpg, image1.jpg and image2.jpg
I used /full/path/to/files/image* in the argfile and still receive 'file not found'

<scratches head>

I'm using 9.13 if that helps.

Thanks again for your assistance :)

B


Phil Harvey

Interesting.  It has never come up that someone wanted to use wildcards in the argfile on Mac/Linux.  You're quite right, this only works in Windows (since there is no shell globbing in Windows, ExifTool is forced to do this internally).

But adding globbing to files in the argfile for Mac/Linux is problematic because there would be no way to disable globbing if you want (say, if you really had a file with a "*" in the name, which is possible on Mac/Linux, but not Windows).

Darnit, foiled again.

Is there any way to do the globbing from your side (with whatever software or script is generating the argfile)?

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

benjamin

Hi Phil,

Perhaps a simple way would be to use a character that is DEFINITELY reserved on all systems as a wildcard rather than '*'? (are there any?)

B

Phil Harvey

There are no reserved characters in Mac/Linux file names.  Any character is possible.  Mac OS will prevent you from using some characters, but there is no restriction for the underlying BSD Unix.

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

benjamin

Hi Phil,

Bugger. Oh well.

Maybe a general -allow_file_name_globbing feature for argfiles/tab files/csv/etc... hehe :)

Anyway. Thanks again for your help. I'll just call discrete instances of the tool in my script for the time being. (or write out the argfile for each matched file)

Cheers

B