Re: Windows paths in glob



Dmitry wrote:
OK, so there's a well-known difficulty with handling Windows-style paths in glob: it doesn't like backslashes, nor does it like spaces. One solution to that is to use Unix-style paths:

glob('C:\Documents and Settings\*'); # Doesn't work
glob('C:/Documents\ and\ Settings/*'); # Works

Problem is, the rest of Perl's built-in file-handling functionality behaves the other way around. For instance, with -d:

-d 'C:\Documents and Settings'; # Works
-d 'C:/Documents\ and\ Settings'; # Doesn't work

Question: is there any way to use the same path string with glob and with the rest of Perl, without having to convert them back and forth?

A long time ago I decided to use opendir() and readdir() instead of glob(). It may not be as 'elegant', but it works flawlessly without escaping spaces.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: Windows paths in glob
    ... in glob: it doesn't like backslashes, ... solution to that is to use Unix-style paths: ... I don't have Windows to test here, but I recall that using either a ... In the examples you gave, the versions with backslashes cannot work, the ...
    (comp.lang.perl.misc)
  • Re: Windows paths in glob
    ... in glob: it doesn't like backslashes, ... solution to that is to use Unix-style paths: ... In the examples you gave, the versions with backslashes cannot work, the ... unless they escape something other than a backslash. ...
    (comp.lang.perl.misc)
  • Re: Windows paths in glob
    ... paths in glob: it doesn't like backslashes, ... One solution to that is to use Unix-style paths: ... perldoc File::DosGlob ...
    (comp.lang.perl.misc)
  • Re: Windows paths in glob
    ... paths in glob: it doesn't like backslashes, ... One solution to that is to use Unix-style paths: ...
    (comp.lang.perl.misc)
  • Re: Windows paths in glob
    ... in glob: it doesn't like backslashes, ... solution to that is to use Unix-style paths: ... is there any way to use the same path string with glob and ... well-formed regexp) you cannot use any filename as a glob pattern and ...
    (comp.lang.perl.misc)