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

#!/usr/local/perl -w use File::Find; use strict; &find(\&wanted, '/rootdata'); sub wanted { /^myscripts$/ && print("$_\n");
it says
Can't cd to (/rootdata/) lost+found: Permission denied at search.pl line 6 myscripts
i have rwe permissions on /rootdata, may be it's not able to access the lost+found or what ever folder, how do i skip those folder, that i don't have permission and how do i display list of files and folder using File::Find, i know without using the File::Find module
help is really needed
opensourcer

"I really don't live on earth, it's just my reflection" "open source is not only technology, but it's a world out there - opensourcer"

Replies are listed 'Best First'.
Re: Skipping unreadable directories with File::Find (or how to test your code)
by jeffa (Bishop) on May 26, 2005 at 18:44 UTC

    I think you are missing something on your end.

    I created a directory, relative to this script:

    use strict; use warnings; use File::Find; &find(\&wanted, 'find_tmp'); sub wanted { /^foo$/ && print("$_\n"); }
    I create the directory find_tmp and three directories inside of it -- each one contained two touched files, foo and bar. I set the permissions of one of those directories to 000 and ran the script:
    [jeffa@server1 perl]$ ./foo.pl
    foo
    Can't cd to (find_tmp/) cannot: Permission denied
     at ./foo.pl line 9
    foo
    
    Looks like File::Find is indeed skipping directories as advertised -- that is, it is not die'ing when it cannot access them due to permissions. (Are you really sure you have the proper permissions?) If you redirect STDERR, you won't get the warning messages:
    [jeffa@server1 perl]$ ./foo.pl 2>/dev/null
    foo
    foo
    

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      ya i noticed "}" at the end of the sub routine, but i need a way to look up into the folder where i have read, execute access, other wise there is no meaning of me writing a code for searching files or folders, i have tried on every folder on my linux box, the code works fine only on my home folder, and fails on other folder inside "/" on whom i have read, excute and even write on some folder and files.

      "I really don't live on earth, it's just my reflection" "open source is not only technology, but it's a world out there - opensourcer"
Re: Skipping unreadable directories with File::Find
by bmann (Priest) on May 26, 2005 at 18:48 UTC
    Those are just warnings and can be disabled by using no warnings "File::Find"; in the appropriate scope.

    Obviously, the script will not find any matching files in those directories where you don't have permissions. If you do need to look in those directories you need to run the script as a user with the authority to do so (or you could use locate or a similar utility for your platform).