Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Filesystem checking

by coec (Chaplain)
on Apr 30, 2004 at 06:48 UTC ( [id://349348]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all

I have a Perl script that traverses a directory structure, processing files as it goes. The script needs to not leave the current filesystem, basicaly, equiv to adding -xdev to Unix find. I'm looking for a better way to do this.

Currently I'm doing equiv to `df . | awk '{print $1}'` and checking that the filesystem is the same. I was looking for a pure Perl solution and all I can think of is using "(stat $dir)[0]".

Are there better ways of doing this?

Thanks

CC

Replies are listed 'Best First'.
Re: Filesystem checking
by Zaxo (Archbishop) on Apr 30, 2004 at 07:05 UTC

    I think your (stat $dir)[0] idea is fine. Another possibility is to use the -l file test. That still calls stat, so it's probably not any improvement.

    You could evade all those stat calls by parsing mount points out of /etc/mtab or the system mount call, then matching paths. That seems messy and has possible inaccuracies, though.

    After Compline,
    Zaxo

Re: Filesystem checking
by pelagic (Priest) on Apr 30, 2004 at 07:29 UTC
    Have you tried this?
    use File::Spec; ($volume,$directories,$file) = File::Spec->splitpath( $path );
    I don't know the internal implementation of it but it might be worth a try.

    pelagic
      I tried this on both AIX and Linux, $volume was '' on both. Worth a try, though...
        I was sorta guessing ... but now I looked into the code:
        For VMS, W32, Mac and OS2 '$volume' means something like drive e.g. 'C:'
        as for Unix its not implemented at all and always returns ''

        pelagic
Re: Filesystem checking
by eserte (Deacon) on Apr 30, 2004 at 08:58 UTC
    Using (stat $dir)[0] is fine. If you're using File::Find, then it may be worth to take a look at the output of find2perl -xdev.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://349348]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-19 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found