extract metadata with EXIFTOOL called from MFC dialog (Windows)

Started by DocDJ, February 01, 2023, 09:06:35 AM

Previous topic - Next topic

DocDJ

I have written a Windows dialog (using MFC) as a wrapper for Exiftool. I have used Exiftool from a batch file with great success, but am having trouble getting the metadata output using my dialog app. My MAJOR difficulty is understanding the use of the -csv option (or if I need to capture STDOUT instead). My 2nd problem is that the -csv documentation uses the terms "import" and "export", but it isn't clear to me as to the "direction" of these terms. Does "import" mean "extract metadata from the image INTO the csv file" or does it mean "import into the image FROM the csv file"? And can I pass a PATH for the image when I start exiftool or must I CD to the directory?

Phil Harvey

Reading faqs 12 and 26 may help.

You can pass a path as the FILE argument to ExifTool if the entries in the SourceFile column of the CSV have the same path.

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

StarGeek

Quote from: DocDJ on February 01, 2023, 09:06:35 AMMy MAJOR difficulty is understanding the use of the -csv option (or if I need to capture STDOUT instead).

The -csv option will list the data in the CSV format as part of STDOUT.  So you will either need to capture STDOUT or redirect it into a file.

QuoteDoes "import" mean "extract metadata from the image INTO the csv file" or does it mean "import into the image FROM the csv file"?

If you use just -CSV, then exiftool lists the data requested from the file to STDOUT in the CSV format.  This is the Export.  If you included a filename, e.g. -csv=file.csv, then exiftool will read the CSV file and attempt to import the data from the CSV into the images.

QuoteAnd can I pass a PATH for the image when I start exiftool or must I CD to the directory?

The "SourceFile" column can either include the full path or a path relative to the current directory.  You still need to include the filenames/directories as part of the command.  So if I have a csv file a entry for ..\Test4.jpg, i.e. file is in the parent directory of the current directory, but my command uses a dot for the current directory
exiftool -csv=file.csv .
Then no edits will be made, as I didin't include the parent directory as part of the files/directories to be processed.  In other words, the CSV file is not a list of files to be processed, it is a lookup table for any files exiftool reads during the command.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

@StarGeek's responses are usually much more comprehensive than mine. :)

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

DocDJ

to all: Thanks for the quick replies. I am not getting ANY output. I am redirecting STDOUT and STDERR to a file. Here is my commandline to EXIFTOOL:
-f -s3 -ImageHeight -ImageWidth -Country -State -City -Sub-location -Description jpgpath  >  mpath
where jpgpath is the full path to the image and mpath is the path to the expected output file (both paths include the respective filenames). Both files are empty. The 2 paths are passed as literals, not variables. 

Phil Harvey

The redirection (>) is done by the shell.  I'm thinking that the MFC dialog runs the command directly and not via a shell.  In this case, use the ExifTool -W option instead:

exiftool -f -s3 -ImageHeight -ImageWidth -Country -State -City -Sub-location -Description jpgpath -W+! mpath
Note that this command will overwrite any existing "mpath" output file, so be careful.

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

DocDJ

I tried the -W+! with and without a space between the option and the path. Still no output. You are correct that EXIFTOOL is NOT running in a shell. It is run via the Windows CreateProcess function specifying it be run inside the JPGPATH's directory, which is also the directory I specify for the output file.

PS. Overwriting is exactly what I want.

Phil Harvey

There should be a space after -W+!, but unless you specify an absolute path then the output will go to whatever working directory MFC uses, so you may have trouble finding the file.

You say it is running in JPGPATH, but I'm guessing it may not be.

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

StarGeek

Just bringing this up because the first post is about using the -csv option, the -csv option cannot be combined with the -W option.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

DocDJ

I removed the -csv. I tried with and without a space after W+! and I have a program called "everything.exe" that searches every drive and folder on my entire PC and it cannot find the output file.
I am mystified.

DocDJ

One thought: does EXIFTOOL need the backslashes to be doubled?

Phil Harvey

ExifTool doesn't need backslashes to be doubled, but I can't speak for your MFC interface.

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

StarGeek

With exiftool, you can use forward slashes for directory paths.

You should test your command and make sure it works on the command line before running it from MFC.  Also, look closer at the docs for running external programs from MFC.  I have no idea about this case, but some programming languages require each argument to be added separately rather than executed as a single string.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

DocDJ

I tried passing the parameter with both single and double backslashes, then with /" instead. No Joy. Finally decided to trap the retcode from the process (with "/"s) and it was -1. Any way to get more info on what it didn't like?

DocDJ

THANKS TO ALL of you for your help.  :)  :)  Once I had the proper options, I decided to trap the error code from EXIFTOOL, which was a -1. Then I took another look at my parameter string. It started with a space. Removed it and it worked. Each piece of metadata appeared on a separate line of my output file. Next I will research how to get them all on one line. ALso, I'll go back to trying with backslashes and see if it works. If it does, I'll report back and specify if doubling is needed. There are MANY things different from ordinary console apps in C++ vs C++ in MFC dialogs. Using the MS CString data type (which helps with string handling) presents its own problems.