http://qs1969.pair.com?node_id=368477

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

hello, how can i get the type of the filesystem?
on both unix and win. 
like fat32, ntfs, ext2,3, mvfs...

Replies are listed 'Best First'.
Re: filesystem type
by Tomte (Priest) on Jun 21, 2004 at 15:57 UTC

    On windows: Win32::FsType(), on unix parse the output of mount -n, under linux

    my @result = (); foreach (split("\n",`mount -n`)) { push @result, (split)[0,4]; } my %result = @result;
    will put the filesystem as value of the key "mountpoint" in the hash %result;

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

      mount -n will know only about supported filessytems, you can try file -s /dev/device,
      pokurcz:# file -s /dev/hda1 /dev/hda1: Linux rev 1.0 ext2 filesystem data (mounted or unclean) pokurcz:# file -s /dev/hda2 /dev/hda2: Linux/i386 swap file (new style) 1 (4K pages) size 124502 p +ages
Re: filesystem type
by rinceWind (Monsignor) on Jun 21, 2004 at 16:40 UTC
    Maybe there's a case for a module here. One that will do the right thing on each platform.

    How about:

    use File::System qw(fstype); ... my $fstype = fstype($filnam);
    Maybe it could do other things, like capacity, freespace.

    --
    I'm Not Just Another Perl Hacker

      hello
      error : can't locate System....
      
Re: filesystem type
by arthas (Hermit) on Jun 21, 2004 at 15:47 UTC

    Hi!

    On Unix you can parse the output of df. I'm unsure about Windows - I don't use it - but I think chkdsk shows you the filesystem type of mounted disks, so you can parse that.

    Hope this helps.

    Michele.

      chkdsk no cause it starts to check the HDD...