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

Hi, I am doing a search on my pc for certain files. How do I write a script that searches all folder except the C:\WINNT folder and its subfolder. Since I am using the Find module I tried it with something like ($File::Find::dir ne "c:\\WINNT\\.")) but this does not work. can someone help me out.
  • Comment on search all folder except certain folders

Replies are listed 'Best First'.
Re: search all folder except certain folders
by Improv (Pilgrim) on Apr 21, 2003 at 19:16 UTC
    From the File::Find perldoc, you'll want to do create a sub that'll filter out the winnt folder from the list of files, e.g.
    sub filter { return (grep !/winnt/i, @_); }
    and pass that code reference under the hash key preprocess as the first parameter to find. I believe this should do what you want. I hope this helps..
      This is not what I wanted. Here a snippet of my code.
      finddepth (\&rename_file_dir , "c:\\" ); sub rename_file_dir { if( /(.*)csscs_ref(.*)/i )# any files or directories { $orig = $File::Find::name ; $concat = $File::Find::dir . "\/$1$new_hostname$2"; rename($orig, $concat) || print "error can't rename $orig to + $concat: $!" } } How can I rewrite the subroutine so that the script looks for all file + that has the substring "csscs_ref" but not in the 'c:\\WINNT' folder +.
      --thanks
Re: search all folder except certain folders
by PodMaster (Abbot) on Apr 22, 2003 at 06:46 UTC
    use File::Spec::Functions; my @path = qw( C:\WINNT\ C:/WINNT/ ); print "$_ => ", canonpath($_),$/ for @path; __END__ C:\WINNT\ => C:\WINNT C:/WINNT/ => C:\WINNT
    You may also wish to checkout File::Find::Rule (some monks really like the interface).


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.