File::Find dies on directory paths which are too long

Discussion in 'Perl Misc' started by wbeldman@gmail.com, Mar 13, 2007.

  1. Guest

    I am trying to traverse the file system on a remote computer from a
    Windows machine to report on specific extensions. Here is the source
    code:
    =====================================
    #! C:\Perl\bin\perl.exe -w
    ####
    # This program was generated by 'find2perl' and is slightly tweaked to
    suit our needs (on Windows).
    # usage is: findext.pl directory extension
    # eg. findext.pl \\cluster\itshome doc

    eval 'exec C:\Perl\bin\perl.exe -S $0 ${1+"$@"}' if 0; #
    $running_under_some_shell

    use strict;
    use File::Find ();

    # Set the variable $File::Find::dont_use_nlink if you're using AFS,
    # since AFS cheats.

    # for the convenience of &wanted calls, including -eval statements:
    use vars qw/*name *dir *prune/;
    *name = *File::Find::name;
    *dir = *File::Find::dir;
    *prune = *File::Find::prune;

    sub wanted;

    if ($#ARGV+1 != 2){
    die "Proper usage:\n\t$0 directory ext\n\tdirectory=$ARGV[0] and
    extension=$ARGV[1]\n";
    }
    if (!(-d $ARGV[0])){
    die "$ARGV[0] is not a valid directory\n";
    }
    # Traverse desired filesystems
    File::Find::find({wanted => \&wanted}, "$ARGV[0]");
    exit;


    sub wanted {
    #Replace \\cluster.../folder/something.mp3 with \\cluster...\folder
    \something.mp3
    $name =~ s/\//\\/g;
    if (/^.*\.$ARGV[1]\z/s){
    print "$name\n";
    }
    }
    =====================================
    The program works great except when I run into a directory which is
    too long. In windows explorer, I can't CD to a path like \\compname
    \sharename\directory\{many subdirectories}\directory because I get:
    "Can't access this folder Path too long". When I use the above program
    it crashes at that point and I get:
    =====================================
    Can't opendir(\\compname\sharename\directory\{many subdirectories}
    \directory): No such file or directory
    at D:\Scripts\dev\Send Reports\MP3 Reports\findext.pl line 30
    Can't cd to \\compname\sharename\directory\{many subdirectories}
    \directory../.. at C:/Perl/lib/File/Find.pm line 896.
    =====================================
    My question is, how would I get around this problematic directory and
    just let my program continue on to all the other directories in that
    share?
    , Mar 13, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    563
  2. Tony  Lay
    Replies:
    1
    Views:
    806
    Tony Lay
    Jul 13, 2009
  3. JVRudnick

    CDOSYS executes but takes TOO TOO long?

    JVRudnick, Feb 20, 2008, in forum: ASP General
    Replies:
    13
    Views:
    272
    JVRudnick
    Feb 28, 2008
  4. Christopher M. Lusardi
    Replies:
    3
    Views:
    174
    Alan J. Flavell
    Oct 19, 2003
  5. nani
    Replies:
    2
    Views:
    152
    comp.llang.perl.moderated
    Mar 14, 2008
Loading...

Share This Page