Is it possible to get machine readable (eg. csv, json, xml...) exiftool output for multiple files in a single file with the output/destination file specified in an ARGS FILE?I understand that to specify output/destination in an ARGS FILE requires
-w, and that
-w will not work with
-csv, so I try to use
-json output instead.
If I try to
output tags of multiple files into a single JSON
file with
destination/file name in ARGS FILE I have the problem that the JSON is malformed.
exiftool -@ /path/to/MyArgsFile.txt
# MyArgsFile.txt
-time:all
/path/to/mypicsfolder
-g1
-ext
jpg
# Append all values to single JSON output file
-json
-W!+
/path/to/MyOutputFile.json
..as expected, appending correctly formed JSON for each file together does not result in a final correctly formed JSON file.
CORRECT JSON FOR SINGLE FILE | [{"json-for-file" : "1"}] |
INCORRECT JSON FOR MULTIPLE FILES | [{"json-for-file" : "1"}][{"json-for-file" : "2"}] | < sort of output exiftool -W!+ gives |
CORRECT JSON FOR MULTIPLE FILES | [{"json-for-file" : "1"},{"json-for-file" : "2"}] | < desired sort of output |
NOTE : JSON is correctly formed using destination file shell redirection in the command line (but I'm hoping to use an ARGS FILE).
exiftool -time:all /path/to/mypicsfolder -g1 -ext jpg -json > /path/to/MyOutputFile.json
From the -w option documentation:
2) If the argument for -w does not contain a valid format code
(eg. %f), then it is interpreted as a file extension, but there
are three different ways to create a single output file from
multiple source files:
# 1. Shell redirection
exiftool FILE1 FILE2 ... > out.txt
# 2. With the -w option and a zero-width format code
exiftool -w+! %0fout.txt FILE1 FILE2 ...
# 3. With the -W option (see the -W option below)
exiftool -W+! out.txt FILE1 FILE2 ...
- Phil
Thanks Phil, but for me...
# 1. (Shell redirection) gives
correctly delimited output :)
exiftool /path/to/IMG_001.JPG /path/to/IMG_002.JPG -datetimeoriginal -json > myOutputFile-ShellRedirection.jsonQuote[{
"SourceFile": "/path/to/IMG_001.JPG",
"DateTimeOriginal": "2021:06:11 13:51:04"
},
{
"SourceFile": "/path/to/IMG_002.JPG",
"DateTimeOriginal": "2021:06:11 13:55:55"
}]
# 2. and # 3. (-W append) give
incorrectly delimited output :(
exiftool -datetimeoriginal -json -W+! myOutputFile-W-append.json /path/to/IMG_001.JPG /path/to/IMG_002.JPG Quote[{
"SourceFile": "/path/to/IMG_001.JPG",
"DateTimeOriginal": "2021:06:11 13:51:04"
}]
[{
"SourceFile": "/path/to/IMG_002.JPG",
"DateTimeOriginal": "2021:06:11 13:55:55"
}]
I wonder if it's possible to get correct (delimited) machine readable output (csv, json, xml...) for multi-file input and single-file output with
-w/W (so I can specify destination file in ARGS FILE) :) ?
I see. Sorry for not reading through your entire first post.
This will be difficult to fix, but I'll look into it.
- Phil
Many thanks.
..and to show appreciation for your amazing tool (and the time it saves me).
I've hit the https://exiftool.org/#donate (https://exiftool.org/#donate) button. ;)
I got the donation, thanks.
This is very tricky because the -W syntax allows you to open any number of output text files based on the flexible format codes which may be used. I'll have to patch ExifTool to remember the state of each output file and add either a delimiter or an opening square bracket depending on whether or not the file was written previously. Then I'll have to delay writing the closing square brackets until after all of the files are processed. This is do-able, and I should be able to have this patch working for the 12.41 release.
- Phil
I see. :)
My current
simple WORKAROUND is a
global search-and-replace on the output file :
SEARCH | (close-bracket new-line open-bracket) | ]\n[ |
REPLACE | (comma carriage-return) | ,\r |
8)