remove the characters / \ ? * : | < > from file name

Started by unific, July 14, 2019, 08:17:09 AM

Previous topic - Next topic

unific

M Doing something wrong but i want to remove the characters / \ ? * : | < > from file name

from the documentation:
A default expression of tr(/\\?*:|"<>\0)()d is assumed if the expression is empty (ie. ${TAG;}). This removes the characters / \ ? * : | < > and null from the printed value. (These characters are illegal in Windows file names, so this feature is useful if tag values are used in file names.)

my command
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"<>\0)()d}_${Make;tr(/\\?*:|"<>\0)()d} image.jpg

${Make;tr(/\\?*:|"<>\0)()d} i get error > was unexpected at this time.
${Make;tr(/)(-)} = working

Can anybody help me

olball

Quote from: unific on July 14, 2019, 08:17:09 AM
my command
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"<>\0)()d}_${Make;tr(/\\?*:|"<>\0)()d} image.jpg
use
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;}_${Make;}" image.jpg

The semicolon after the tag name does apply the default expression to remove the invalid characters.

StarGeek

Quote from: unific on July 14, 2019, 08:17:09 AM
my command
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"<>\0)()d}_${Make;tr(/\\?*:|"<>\0)()d} image.jpg

As olball mentioned, you don't need to list the full replace in this case.  The trailing semicolon is enough.

But to address the problem in this case, you have an unescaped double quote in the middle of the command.  I'm assuming you're using windows, so you would have to escape the double quote and you do that by tripling the double quote, though sometimes a backslash will also work.
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"""<>\0)()d}_${Make;tr(/\\?*:|"""<>\0)()d}" image.jpg

edit: missing trailing quote from copy/pasted command
* 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).

olball

Hi StarGeek,

I noticed the unmatched quote.

Quote from: StarGeek on July 14, 2019, 12:33:44 PM
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"""<>\0)()d}_${Make;tr(/\\?*:|"""<>\0)()d}" image.jpg
But the triple quote does not work for me (also when adding the missing closing quote ;-))
It seems the triple quote and the <> sign does not work together. Removing <> from the transliterate command works with the triple quote, strange.

PS: After some testing I found it works if the triple quote is behind the <> signs. So
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|<>"""\0)()d}_${Make;tr(/\\?*:|<>"""\0)()d} image.jpg

But this is the same as
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;}_${Make;}" image.jpg
with less typing.

unific

Quote from: StarGeek on July 14, 2019, 12:33:44 PM
Quote from: unific on July 14, 2019, 08:17:09 AM
my command
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"<>\0)()d}_${Make;tr(/\\?*:|"<>\0)()d} image.jpg

As olball mentioned, you don't need to list the full replace in this case.  The trailing semicolon is enough.

But to address the problem in this case, you have an unescaped double quote in the middle of the command.  I'm assuming you're using windows, so you would have to escape the double quote and you do that by tripling the double quote, though sometimes a backslash will also work.
exiftool -f -d  %Y-%m-%d_%H-%M-%S "-filename<${CreateDate}${Model;tr(/\\?*:|"""<>\0)()d}_${Make;tr(/\\?*:|"""<>\0)()d} image.jpg
This did not work for me and yes i'm using windows
I still get error
> was unexpected at this time.

StarGeek

Did you try olball's suggestion?  Given what you're trying to do, you should use the simpler version rather than try and work around Windows strangeness.
* 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).

unific

Quote from: StarGeek on July 14, 2019, 02:43:24 PM
Did you try olball's suggestion?  Given what you're trying to do, you should use the simpler version rather than try and work around Windows strangeness.

Yes, That worked

obetz

Quote from: StarGeek on July 14, 2019, 12:33:44 PM
But to address the problem in this case, you have an unescaped double quote in the middle of the command.  I'm assuming you're using windows, so you would have to escape the double quote and you do that by tripling the double quote, though sometimes a backslash will also work.

StarGeek, can you provide any reference material for "triple quote marks"?

I never saw triple quote marks and I'm rather sure that backslash escaping is the way proposed by Microsoft.

Oliver

StarGeek

Hmmm...  I'm not sure where I came across that.  I do know that there have been times where I was doing an extremely long and complex exiftool command where using multiple (over 5) \" failed and I had to use three quotes to embed a single quote.

A google search on the subject shows the whole thing is a mess.  I believe this StackOverflow answer might be where I originally came across it.  But then there's this extensive StackOverflow answer which makes for an interesting read, though it's focus is on batch and doesn't mention triple quoting.

I've long since given up on the subject and whenever possible, I use the -E (escapeHTML) option and &quot;
* 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).

obetz

Quote from: StarGeek on July 15, 2019, 10:54:55 AM
A google search on the subject shows the whole thing is a mess.

I fully agree. And you have to quote even more in cmd files.

And the PAR packer pp (which I would like to eliminate from ExifTool) implements it's own mangling: https://github.com/rschupp/PAR-Packer/blob/master/myldr/boot.c

Thanks for the hint about triple quotes, that's new to me. It's also not explained here:
https://docs.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments?view=vs-2019

I think I need to add more weird patterns to my test suite.

BTW: The caret quoting mentioned in the first stackoverflow article works differently here. It doesn't escape double quotes but a caret at the end of the line has some magic.

Oliver