Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: true from (-e "") on Windoze

by CarolinaPerler (Acolyte)
on Jul 02, 2012 at 19:15 UTC ( [id://979509]=note: print w/replies, xml ) Need Help??


in reply to Re: true from (-e "") on Windoze
in thread true from (-e "") on Windoze

if ($file) returns true, also because the variable has content, two double quotes. I think I'm going to have to just check to see if my $file variable contains a pair of double quotes and only a pair of double quotes. 'Seem like a hack, though. 'Seems like the '-e' test operator would return false on this case.

That's what makes me wonder if Windoze actually uses the empty double quotes as some kind of file system object/entity. That would make the '-e' test think the empty-double-quote-thing was real and existed..... Don't know that much about the various file system types and how Perl on Windows handles them.

Replies are listed 'Best First'.
Re^3: true from (-e "") on Windoze
by BillKSmith (Monsignor) on Jul 03, 2012 at 03:46 UTC

    Windows uses double quotes to solve a problem caused by file (or directory) names which contain spaces.

    dir "C:\Program Files\" Works as intended

    dir  C:\Program Files\ File not found

    dir "" Displays current directory

Re^3: true from (-e "") on Windoze
by frozenwithjoy (Priest) on Jul 02, 2012 at 19:26 UTC
    OK, how about this? (I've tested and it is working correctly for $file = '""'; on OS X.)
    for ($file) { say "nope (empty quotes)" when /""/; say "yep" when -e $file; default { say "nope (doesn't exist)"} }
      Yeah, the odd behavior only occurs on Windoze. UNIX/Linux/Mac work just as you'd expect, returning false for the '-e' on a pair of empty double quotes.
        Did you get a chance to test this code? I think it might solve your problem since the first thing it does is look for a match to double quotes before checking whether the file exists.
Re^3: true from (-e "") on Windoze
by ww (Archbishop) on Jul 02, 2012 at 22:00 UTC
    I think you're misinterpreting comments preceding Re^2: true from (-e "") on Windoze; I think the fact that the VALUE of $file is -- per se -- true is borking your expectations.

    I don't recall any version of windows accepting "" or '""' or """" as a filename or filename element ...or any of the DOS/doze FS using "", et al, for anything.

Re^3: true from (-e "") on Windoze
by frozenwithjoy (Priest) on Jul 02, 2012 at 19:21 UTC
    Ya, I didn't catch that they were quotes within quotes. Out of curiosity, why/how is that happening?
      My code is being fed, so to speak, by another application over which I have no control. Every now and again, when the feeder is asked for a list of files, it returns one or more elements in the array that contains just a pair of empty double quotes.

      Oddly, at a Windows command prompt, you can do 'cd ""' and it does not complain. It doesn't go anywhere, but, it doesn't complain.
        Oddly, at a Windows command prompt, you can do 'cd ""' and it does not complain. It doesn't go anywhere, but, it doesn't complain.

        Don't assume cmd.exe (or command.com) behave like a unix shell. Quite the opposite is true. 30 years of bug-compatible extensions give both a very unique smell. Whatever happens in those two dinosaurs has nearly nothing in common with the underlying APIs.

        Note that unquoting happens inside the application, not in the shell -- except when you call a shell buildin like cd/chdir. Now look at the fine differences:

        Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\alex>cd C:\Users\alex C:\Users\alex>cd "" C:\Users\alex C:\Users\alex>cd . C:\Users\alex>

        cd "" behaves like cd without arguments, i.e. it prints the current directory. cd . actually changes the current directory to *drumroll* the current directory! So it does not print anything.

        Alexander

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://979509]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found