in reply to Re^3: true from (-e "") on Windoze (" is an illegal filename character
in thread true from (-e "") on Windoze

I agree that the 'problem' has nothing to do whith perl. It makes sense to consider double quotes around a windows filename as required if the filename contains whitespace and optional otherwise. From this view, the dir command followed by two double quotes should display the same thing as the dir command without them - the current directory. This logic requires other system functions to also treat the null file name as the current directory.
  • Comment on Re^4: true from (-e "") on Windoze (" is an illegal filename character

Replies are listed 'Best First'.
Re^5: true from (-e "") on Windoze (" is an illegal filename character
by afoken (Chancellor) on Jul 05, 2012 at 20:33 UTC

    You are mixing command line parsing in command.com / cmd.exe and the Windows-APIs.

    Unlike in Unix, command line parsing is the job of the invoked program (and not that of the shell) on Windows, this typically happens in the C RTL. The command interpreters themself also parse their input, but only to find the executable or build-in command and to handle redirections. The build-in commands (dir, cd, ...) must also parse their argument string, probably using the same or very similar routines.

    After that parsing has happened, quotes and escape characters are gone, and the program or build-in command has a list of (unescaped) arguments, some of them are passed to API functions. The API functions do not remove quotes:

    X:\>dir 979536.exe Volume in drive X is RAMDISK Volume Serial Number is 065B-0000 Directory of X:\ 05.07.2012 22:04 121.535 979536.exe 1 File(s) 121.535 bytes 0 Dir(s) 129.867.776 bytes free X:\>dir "979536.exe" Volume in drive X is RAMDISK Volume Serial Number is 065B-0000 Directory of X:\ 05.07.2012 22:04 121.535 979536.exe 1 File(s) 121.535 bytes 0 Dir(s) 129.867.776 bytes free X:\>perl -Mautodie -e "open $f,'979536.exe'" X:\>perl -Mautodie -e "open $f,chr(34).'979536.exe'.chr(34)" Can't open($fh, '"979536.exe"'): Invalid argument at -e line 1 X:\>type openfail.c #include <stdio.h> #include <errno.h> int main(int argc, char ** argv) { FILE * f; if ((f=fopen("979536.exe","r"))==NULL) { perror("open without quotes"); } else { fclose(f); } if ((f=fopen("\"979536.exe\"","r"))==NULL) { perror("open with quotes"); } else { fclose(f); } return 0; } X:\>gcc -Wall -pedantic -o openfail.exe openfail.c X:\>.\openfail.exe open with quotes: Invalid argument X:\>

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)