PerlingTheUK has asked for the wisdom of the Perl Monks concerning the following question:

Dearest Monks,
I have a problem with file paths in windows. I need to glob for all files in a directory. Unfortunately the directory includes whitespaces and therefore falls over:
@fs = glob("D\:\/Leamington\ 24\.11\.05\/Leamington" . "\/*.dat")
This only returns D\:\/Leamington
I used quotemeta to convert the filepath and files at the location exist and can be found if I remove the whitespace.
If I try using File::DosGlob @fs is empty.

Cheers,
PerlingTheUK

Replies are listed 'Best First'.
Re: Win32 File Path problem
by Corion (Patriarch) on Nov 25, 2005 at 12:33 UTC

    If you want sane behaviour for glob, you should overwrite it with the sane implementation in File::DosGlob:

    use File::DosGlob qw(bsd_glob); print join "\n", glob "d:/Leamington 24.11.05/Leamington/*.dat";

    Also, you don't need to use backslashes on Win32 - the Win32 API understands forward slashes as directory delimiters as well.

Re: Win32 File Path problem
by GrandFather (Saint) on Nov 25, 2005 at 11:02 UTC

    From the File::DosGlob documentation:

    If you want to put in literal spaces in the glob pattern, you can escape them with either double quotes, or backslashes. e.g. glob('c:/"Program Files"/*/*.dll'), or glob('c:/Program\ Files/*/*.dll').

    DWIM is Perl's answer to Gödel
      I know, but I did not know that the escaped forward slashed quotemeta inserts are not supported by DosGlob. I have replaced quotemeta with  $s =~ s/\ /\\ /g; and it works fine now.
      Thanks for the help.

      Cheers,
      PerlingTheUK