Set Different Delimiter Than Newline for Printing Tag Values

Started by mpkiCyaL, March 31, 2023, 12:02:43 PM

Previous topic - Next topic

mpkiCyaL

What's up?

$ exiftool -r -q -q -printFormat '${FileName#}' -if '$Track1:MediaDuration# < 300' . | xargs rm

rm: cannot remove '99633372.mp4'$'\r': No such file or directory

I can, of course, strip the newline, but I'm wondering if I can tell ExifTool to choose a different delimiter like a null char?
I also know I can delete files without piping to rm, but I think I prefer to pipe to rm than edit the System:Directory tag or something like that..

Thanks!

StarGeek

Off hand I can't think of anything, but two things might help.  First, according to this xargs man page, "xargs reads items from the standard input, delimited by blanks ... or newlines".  And this ServerFault answer gives the -d option as a way to define a custom delimiter.

One thing that pops out about your command, though, is that you are passing the filename, but you are using the -r (-recurse) option, so any file in a subdirectory will have the name passed but not the directory, which would lead to a file not found error with rm.
* 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).

Phil Harvey

It is safer to use ExifTool to move the offending files to a trash directory, then delete them later.  Passing the output of ExifTool to rm directly seems a bit dangerous.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Phil Harvey on March 31, 2023, 01:48:06 PMPassing the output of ExifTool to rm directly seems a bit dangerous.

That made me remember what you said here where exiftool calculates an approximate duration.  That might lead to problems with files that have incorrect header data.
* 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).

mpkiCyaL

StarGeek - ahhhh...good catch regarding -r, that's embarrassing. Oh well, good that you guys are around to catch these things :)
Phil - you're right, it's not my best thinking, seeing as I don't write perfect code (like combining printing FileName with -r), it seems high risk to delete like that, leaves no room for errors, I will drop the rm.

Thanks