Beware of leading blanks in filenames

Started by Beholder3, October 23, 2011, 11:26:03 AM

Previous topic - Next topic

Beholder3

Hi Bogdan,

I just spent quite some worried time find a cause of an error and I want to share what I found:

I did import some DNG pictures into Lightroom and changed the filesnames automatically there using a new format.
What I didnt realize (it's not easy to see this on screen in a simple textbox) is that my renaming changed all filenames to start with a leading blank/space character.
This leads to exiftoolGUI to show results in the middle view pane in camera view but nothing at all in the right hand detail pane. Only a cryptic error.
As I checked with commandline exiftool I could see that exiftool itself has no issues and works as normal.

Seems to me there is a small bug in exiftoolGUI...

BogdanH

Hi,
Interesting. You said you've checked with commandline, and there is no problem... I've tried with various files (raw and jpg) and as it seems, there is.

Question for Phil:
Assume I have file " img.jpg" inside c:\aa directory. That is, "c:\aa\ img.jpg" is complete file path (notice, that first character of filename is space character).
Now, if I execute:
exiftool -S "c:\aa\ img.jpg"
-everything is fine.
But if I already "reside" inside c:\aa directory and execute:
exiftool -S " img.jpg"
-exiftool returns "Error opening file".

Mind to comment? Having (needing) blank first character in filename is quite rare, though.

Bogdan

Phil Harvey

Interesting that this hasn't ever come up until now.  This is a bug in ExifTool.  It won't accept a filename with a leading space.  I will fix this in the next release.

Thanks for pointing this out.

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

Beholder3

Ok, what I did exactly is I dragged/dropped a file (with leading blank) in windows onto the "exiftool(-k).exe" file, which resided in a different directory than the picture file. That worked/works and showed results.

At least it confirmed to me that the metadata were still there and not fully corrupted as I had feared first.

Phil Harvey

If you specify a directory then the leading space isn't a problem.  Even using "./ img.jpg" gets around the problem.  When you drag/drop, I am sure that Windows includes the directory name, which explains why this works.

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

Phil Harvey

I just checked my Perl programming book.  It says:

    In order to open a file with arbitrary weird characters in it,
    it's necessary to protect any leading and trailing whitespace, like this:

        $file =~ s#^(\s)#./$1#;
        open (FOO, "< $file\0");

    But we've never actually seen anyone use that in a script...


Doh.  I will be doing this in ExifTool 8.69.

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