in reply to Re: Re: Re: Re: Re: file (mp3) list shown on website as links
in thread file (mp3) list shown on website as links
sub wanted { -l && !-e && print "bogus link: $File::Find::name\n"; }
perldoc perlfunc will show you a list of all the file test functions available. -l means 'is a symlink' and -e means 'file exists'. What File::Find does is apply the 'wanted' sub (or any other sub-ref passed) to every file it finds (with $_ locally set as the filename, having chdir-ed to any directory it finds), so in this case it checks first of all if the file is a symlink (-l), and then if the file doesn't actually exist (-e). If this is true then it tells you that that link is broken (using $File::Find::name which is the fully qualified file name, relative to where you are) So, say we actually wanted to find all .mp3 files. We'd use something like:
sub wanted { return unless -f && /\.mp3$/; print $File::Find::name, "\n"; }
Or, you could push them to an array, or whatever. Then you just call this as: find (\&wanted, $BASEDIR)
Tony
|
|---|