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?
Reading faqs 12 (https://exiftool.org/faq.html#Q12) and 26 (https://exiftool.org/faq.html#Q26) 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
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 (https://exiftool.org/exiftool_pod.html#csv-CSVFILE) 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.
@StarGeek's responses are usually much more comprehensive than mine. :)
Thanks
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.
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
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.
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
Just bringing this up because the first post is about using the -csv option, the -csv option cannot be combined with the -W option.
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.
One thought: does EXIFTOOL need the backslashes to be doubled?
ExifTool doesn't need backslashes to be doubled, but I can't speak for your MFC interface.
- Phil
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.
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?
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.
Use -T instead of -s3 to get the output all on one line (tab separated).
- Phil
Backslashes in the paths (image and output file paths) work but must be doubled.
Forward slashes do not have to be doubled because Windows does not care about them in parameter strings. Of course, the called program must be able to handle them, which EXIFTOOL does very nicely.
So I am happily getting my metadata into an output file, using the -T -s3 and -W+ options. However, the tabs written between values get replaced by the file I/O system as 3 spaces. (This also happens for tabs as part of a header written by other parts of my program.) Is there a way to get exiftool to use something other than a tab? I tried switching -T to -csv (and got no output at all), so I suspect that -csvDELIM won't help.
As mentioned, -csv can't be combined with -W. Other than that, you should get an output.
You should really read the -csv option documentation. It contains some hints that may be useful to solve your problems.
- Phil
Per your previous comments, when I switched to -CSV, I had removed the -W option.
After numerous unsuccessful attempts to specify a filename for the CSV output, I discovered that exiftool would write the output to STDOUT. (So I wrote a function to redirect STDOUT to a file.) When I renamed that file as myout.csv (after running exiftool), it opened properly with Excel. Is there any way of specifying the actual path to that file? (I could not figure out a way to specify a file using the % formatting options, because every attempt caused exiftool to treat that file as another image input file.
The -o option caused the same effect.
Please reread this entire thread and read the links. You're asking questions which have already been answered.
For example, in the third post I answer
Quote from: StarGeek on February 01, 2023, 11:13:27 AMThe -csv option (https://exiftool.org/exiftool_pod.html#csv-CSVFILE) 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.
Sorry, I did read them, but I had disregarded the stdout note, assuming that an existing option might be a way to do it without using stdout. (I assumed that the note was just an FYI that a developer could use to see the csv data). Also, I was concerned that other data (such as messages from exiftool) might also be there and mess up my post-processing. It wasn't clear (to me), that stdout was the ONLY way to get the output other than -W, which didn't let me use commas (the tabs were being replaced by the system, leaving no parse-able text to split the data out later.)
-o sounded like a good prospect, but I couldn't figure out a way to do that. Also, all the capabilities of CSVFILE seem to be relegated to reading from the csv file, not building one.
One other major problem with STDOUT is that I plan to process many directories in one run of exiftool, each having their own CSV file. That would mean closing, renaming the STDOUT file and creating a new one for each of those directories. Not difficult, but it slows down the operation. I have lots of directories to process and do it frequently as the files in each directory get updated/replaced.
I was able to combine the -p and -W+ options to get the effect of -CSV without having to do redirection of stdout (which proved to be problematic). I couldn't use -csv, because the tabs in the csv files get changed (by Windows) into spaces by the file system. Commas provided by the -p format rules make for easy post-processing.
Thanks for a great program!