I had some code and I just hacked some changes..this is a prototype of how to use File::Find. The find() function will visit every file below the starting path that you specify and it will call a subroutine for each of those files. Note that a directory is a FILE! This sub cannot return any values except by manipulating something at a higher lexical scope.

The print_all_files subroutine doesn't do anything if it sees a plain file. If it sees a directory, it opens it and reads the names and does something with them. The code below is a bit strange as there is a provision to keep going if a directory doesn't open. There was a different file handle than STDOUT, but sdtdout will get you started. I didn't know if you meant total file path >250 chars? or actual file name, although I must say that a 250 char actual file name is extreme! You can change the grep below to select what you want. The original print statement was more complex, but you can just leave the map{} in there.

I probably would do some small things differently now if I was starting from scratch, but it runs and does illustrate the basic idea of how to use find(). Basically run this code, see what it does and then adapt to what you need. I leave the polishing up to you.

#!/usr/bin/perl -w use strict; use File::Find; my $ROOT_DIR = "C:/"; #something like "$ENV{'HOME'}" on Unix.. find (\&print_all_files, "$ROOT_DIR"); sub print_all_files { return if !-d || !stat; #on some OS'es, this stat is needed my $full_dir_path = $File::Find::name; print STDOUT "$full_dir_path\n","-" x length($full_dir_path),"\n"; if (!opendir (D,$_)) { print STDERR "Could not open directory $full_dir_path\n\n"; die; #or just do a return() to keep going.... } print STDOUT map { sprintf "%s \n",$_; } #grep {length($_)>250} #maybe here? #grep {length("$full_dir_path/$_") >250) maybe? sort grep{ !-d "$full_dir_path/$_"}readdir D; print STDOUT "\n"; close D; }
Example output:
C:/91836f37983a8346dad3/i386 ---------------------------- filterpipelineprintproc.dll msxpsdrv.cat msxpsdrv.inf msxpsinc.gpd msxpsinc.ppd mxdwdrv.dll xpssvcs.dll C:/Calendar ----------- calfaq.zip

In reply to Re: Identifing all filenames over 250 letters long by Marshall
in thread Identifing all filenames over 250 letters long by Win

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.