in reply to Restrict file search within current filessystem using wanted subroutine
Hi madparu,
There is a little-known feature of File::Find from find2perl, the variable $File::Find::topdev, which holds the device number of the path currently being searched under, which you can compare with the device number of the current file (stat). Stick the following at the top of your wanted function, and your search will be limited to the filesystems of the paths which you tell File::Find::find to search under.
if ( $File::Find::topdev != (stat)[0] ) { $File::Find::prune = 1; return }
Update: Fixed stat vs. stat(_), apologies. My test code was doing a stat beforehand, so stat(_) worked fine. But if the piece of code above is the very first thing in your wanted function, you should stat $_ first, and only then use the special filehandle _. (The exception is when the follow option is set, then File::Find guarantees that an lstat has been called.)
And by the way, Use strict and warnings!
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Restrict file search within current filessystem using wanted subroutine
by madparu (Initiate) on Apr 28, 2016 at 12:40 UTC | |
by haukex (Archbishop) on Apr 28, 2016 at 12:57 UTC | |
by madparu (Initiate) on Apr 28, 2016 at 13:56 UTC | |
by Anonymous Monk on May 12, 2016 at 09:27 UTC | |
by haukex (Archbishop) on May 12, 2016 at 09:47 UTC | |
by Anonymous Monk on May 12, 2016 at 10:41 UTC | |
| |
by afoken (Chancellor) on May 12, 2016 at 20:25 UTC |