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
| [reply] [Watch: Dir/Any] [d/l] [select] |
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)"}
}
| [reply] [Watch: Dir/Any] [d/l] [select] |
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.
| [reply] [Watch: Dir/Any] |
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.
| [reply] [Watch: Dir/Any] |
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. | [reply] [Watch: Dir/Any] [d/l] [select] |
Ya, I didn't catch that they were quotes within quotes. Out of curiosity, why/how is that happening? | [reply] [Watch: Dir/Any] |
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.
| [reply] [Watch: Dir/Any] |
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". ;-)
| [reply] [Watch: Dir/Any] [d/l] [select] |