in reply to Identifing all filenames over 250 letters long

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