ExifTool does not read files with certain characters in filenames

Started by newsailor, December 12, 2023, 07:01:15 PM

Previous topic - Next topic

newsailor

OS: Windows 11
Ver: 12.70

I downloaded a video from YouTube and wanted to see its codec information, so I ran it through ExifTool(-k) via drag-and-drop, but it responded "file not found".
After inspecting a little, I think I've found what the issue is.

I use YT-DLP to download videos from video websites. YouTube allows users to put characters like pipes and colons (|:) in their videos, but Windows considers these illegal characters, so YT-DLP does a clever thing and replaces these characters with their full-width equivalents.
When these files are passed to ExifTool, it doesn't know how to handle those characters and throws execution.

You can replicate this by making a text file called ":.txt" on a Windows desktop and dragging it to ExifTool; it will choke.
To make sure we're all using the same characters here, the BabelStone What-Is-It page is immensely useful; I am referring to full-width colons (U+FF1A : FULLWIDTH COLON) and pipes (U+FF5C : FULLWIDTH VERTICAL LINE) which are valid for filenames but not for ExifTool.

Any help appreciated.

Neal Krawetz

Are you quoting the filename?
Quotes work fine for me:

$ ls > ": .txt"
$ exiftool ": .txt"
ExifTool Version Number         : 12.70
File Name                       : : .txt
Directory                       : .
File Size                       : 1644 bytes
File Modification Date/Time     : 2023:12:12 17:09:05-07:00
File Access Date/Time           : 2023:12:12 17:09:05-07:00
File Inode Change Date/Time     : 2023:12:12 17:09:05-07:00
File Permissions                : -rw-rw-r--
File Type                       : TXT
File Type Extension             : txt
MIME Type                       : text/plain
MIME Encoding                   : us-ascii
Newlines                        : Unix LF
Line Count                      : 118
Word Count                      : 152

Oh, I just noticed that you said 'Windows'.
I'm on Linux. I bet the Windows drag-drop interface isn't quoting filenames.

newsailor

I don't believe it's an issue of quoting. I can pass the path to ExifTool using PowerShell:

start-process "exiftool(-k).exe" -ArgumentList "`":.txt`" -k" -NoNewWindow -Wait
And it gives me the same error (see attachment).
If quotes weren't being passed properly, I wouldn't expect to see the filename reflected correctly and verbatim in the "file not found" error text.

StarGeek

My standard copy/paste

See FAQ #18.

Windows CMD is has a lot of problems when it comes to non-ASCII characters.  The options in FAQ 18 may help.

In my case, those options never did work, but this StackOverflow answer fixed the problem for me.  Unfortunately, it also has the side effect of changing the fonts of some older programs and causing problems with their GUIs. .  If you use that option, you'll have to test it and see if the problems are acceptable.
* 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).

newsailor

This just affects terminal windows, though. Are you certain this would also affect drag-and-drop?
EDIT: Using "chcp 65001" does not affect this, the issue persists.

StarGeek

Exiftool is still a command line only program and dragging/dropping won't change this. A non-interactive command line is pulled up to display the results.

I'm not sure if the drag/drop ability is a property of the Perl PAR packer which is used to create the Windows "executable"* or if the same thing would work if you had Perl setup and tried drag/drop onto the Perl script directly.

* The Windows "Executable" is basically a self extracting zip file that includes a minimal Perl processor. The code and processor is extracted to your %TEMP% directory and run from there.
* 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).

FrankB

I just checked it. You can 'drag and drop' files from Windows explorer into ExifToolGui, and it will open filenames with 'UTF8' characters. Now you may not want to start using ExifToolGUI and stick with ExifTool, but to give you an idea what I changed in ExifToolGui V6.2.0 to get it working.

I always create an ARGS file that contains these lines:

-CHARSET
FILENAME=UTF8
-CHARSET
UTF8
-API
WindowsWideFile=1

-CHARSET
FILENAME=UTF8
Tells Exiftool that the filenames are encoded in UTF8

-CHARSET
UTF8
Tells Exiftool to produce output UTF8 encoded. Maybe not needed, but likely the output will also contain UTF8 chars (Filename for example)

-API
WindowsWideFile=1
Tells Exiftool to use IO routines supporting widechars.

I dont know how you can do that using your method. Perhaps you could try to put those lines in a config file?

Hope it helps




StarGeek

Yes, the ExiftoolGUI uses the -stay_open option and an Args file (see -@ (Argfile) option).  The Args file passes text directly to exiftool and bypasses the command line's normal processing of the command.  This is why you don't quote arguments and can't redirect/pipe the output in an Args file.
* 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).

FrankB

I couldn't get it to work using a config file, but this little CMD file makes a difference.
Copy and paste this on your Desktop and name it something like Exiftool.Cmd. You can drag and drop a file to the newly created Cmd file. It will read filenames with UTF8 characters.

I can believe that there will be better solutions than a cmd file, but it proves that the concept with an args file works.

@echo off
setlocal enabledelayedexpansion enableextensions
rem
rem Get command line. Can be dropped
set ETPARM=%*
rem
rem Strip " that can be added when you have space
set "ETPARM=%ETPARM:"=%"
chcp 65001
rem
rem Create Args file, with the options like ExifToolGui does.
set ARGS="%TEMP%\exiftool.args"
echo ^-CHARSET>>%ARGS%
echo ^FILENAME=UTF8>>%ARGS%
echo ^-CHARSET>>%ARGS%
echo ^UTF8>>%ARGS%
echo ^-API>>%ARGS%
echo ^WindowsWideFile=1>>%ARGS%
echo ^!ETPARM!>>%ARGS%
rem
rem Execute Exiftool.
exiftool -@ %ARGS%
rem
rem Remove Args file
del %ARGS%
pause

drop.jpg
greek.jpg

if the options are omitted, it will give an error. That proves that the file really contains UTF8!
@echo off
setlocal enabledelayedexpansion enableextensions
rem
rem Get command line. Can be dropped
set ETPARM=%*
rem
rem Strip " that can be added when you have space
set "ETPARM=%ETPARM:"=%"
chcp 65001
rem
rem Create Args file
set ARGS="%TEMP%\exiftool.args"
echo ^!ETPARM!>>%ARGS%
rem
rem Execute Exiftool.
exiftool -@ %ARGS%
rem
rem Remove Args file
del %ARGS%
pause
nogreek.jpg