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

Is it possible to glob a UNC path? If not, is there another way to get a list of files from a UNC folder so I can run stats on each file?

Below is code that can read a folders file list if I sepcify a drive letter. When I share the folder and use the UNC name I can't read the folders contents.

Thanks in advance.

use strict; use warnings; use Data::Dumper; my $path = 'C:\\junk\\*'; my @angle_files1 = < $path >; my @glob_files1 = glob $path; my $unc = '\\\\machine_name\\junk\\*'; my @angle_files2 = < $unc >; my @glob_files2 = glob $unc; print Dumper $path, @angle_files1, @glob_files1; print Dumper $unc, @angle_files2, @glob_files2; print "\n\nDone\n";

Replies are listed 'Best First'.
Re: globing unc path
by ikegami (Patriarch) on Nov 08, 2007 at 04:04 UTC

    aha! I looked into the problem and found that \ is an escape character in glob expressions so \\server\share is being interpreted as \server\share.

    >perl -le"print for glob shift" \\tribble05\c$\* >md \tribble05\c$\foo >perl -le"print for glob shift" \\tribble05\c$\* \tribble05\c$\foo >>perl -le"print for glob shift" \\\\tribble05\c$\* \\tribble05\c$\AUTOEXEC.BAT ... >perl -le"print for glob shift" //tribble05/c$/* //tribble05/c$/AUTOEXEC.BAT ...

    The \ doesn't need to be doubled in front of "*" because of hack used on Windows builds. From bsd_glob.c:

    /* To avoid backslashitis on Win32, * we only treat \ as a quoting character * if it precedes one of the * metacharacters []-{}~\ */
      The //machine_name/junk/* worked! Thanks ikegami!
Re: globing unc path
by aquarium (Curate) on Nov 07, 2007 at 22:38 UTC
    UNC browsing is blocked in some environments...to help prevent virus spread. in such situations you have to map the UNC to a drive letter, and glob that.
    the hardest line to type correctly is: stty erase ^H

      It's not (just) environmental.

      >dir /b \\tribble05\c$\* AUTOEXEC.BAT ... >perl -le"print for glob shift" \\tribble05\c$\* >perl -le"print for glob shift" c:\* c:\AUTOEXEC.BAT ... >perl -le"opendir $dh, shift; print for readdir $dh" \\tribble05\c$ AUTOEXEC.BAT ...
      I don't think it's blocked. I can do a  dir \\machine_name\junk from a command window and see the directory.