Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

File::Find traversing a link into a mounted flash drive

by swampyankee (Parson)
on Feb 05, 2016 at 17:40 UTC ( #1154491=perlquestion: print w/replies, xml ) Need Help??

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

I did a quick search, but didn't quite find anything that was sufficiently close to be an answer

I'm trying to use File::Find to find image files, so I can randomly change my wallpaper. I know; it's a silly task ⌣. My problem is that I have a bunch of image files on a flash drive, and File::Find won't follow a symbolic link to the contents of the flash drive. I suspect it's because File::Find, even when $File::Find::follow is set won't recurse into a different file system.

I'm using Fedora 21, Perl v5.18.4, File::Find version 1.23.

sub image_search { my $name = $File::Find::name; my $dir = $File::Find::dir; my @globbed; my @temp; my $images = '(png$)|(jpg$)|(gif$)|(jpeg$)'; if (-l $name) { print "processing link named $name\n"; @globbed = glob("$name/*"); } else { print "processing directory named $dir\n"; @globbed = glob("$dir/*"); } if (@globbed) { @globbed = grep {m/$images/i} @globbed; $image_list{$dir} = [@globbed]; } } ## end sub image_search
Sorry for the a) less-than-optimal code design and b) absence of comments.

Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Replies are listed 'Best First'.
Re: File::Find traversing a link into a mounted flash drive
by RonW (Parson) on Feb 05, 2016 at 18:48 UTC

    When running, do you get a "processing link" message for the symlink'ed filesystem? If so, you can use readlink to see if the link is to another filesystem, then call File::Find::find with the target of the link as the start point.

    Disclaimer: Not tested.

      No, and thanks!


      Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

        In that case. I would suggest that every time you enter a new directory, scan it yourself for symlinks, then call File::Find::find for each target that is on a different filesystem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1154491]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2020-09-20 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (121 votes). Check out past polls.

    Notices?