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

Does anyone know how can I get the available space in a partition using as input a directory?
This would have to work on Linux, Mac and Windows, and be supported by Perl4 :P

Also a solution without external libraries would be better :)
I already have a solution, I think, but it's really ugly!

Thanks
  • Comment on Get the available space in a partition using as input a directory?

Replies are listed 'Best First'.
Re: Get the available space in a partition using as input a directory?
by Old_Gray_Bear (Bishop) on Jul 12, 2013 at 18:21 UTC
    Perl 4 was 'functionally stabilized' in 1993. You might be better served by migrating the application to a currently supported version of Perl. I suspect that your client may well not want to hear that....

    ----
    I Go Back to Sleep, Now.

    OGB

Re: Get the available space in a partition using as input a directory?
by daxim (Curate) on Jul 12, 2013 at 17:05 UTC
    You need to figure out how to make system calls in Perl4. stat returns the device number for the directory entry, statvfs returns the available space for that device/partition.
Re: Get the available space in a partition using as input a directory?
by Not_a_Number (Prior) on Jul 12, 2013 at 19:10 UTC

    You missed this bit from the OP:

    This would have to work on Linux, Mac and Windows (my emphasis)

    Neither stat nor statvfs work on Windows.

    Here's a kludge to get the available space on your current Windows drive:

    my $free = ( split ' ', qx{ dir|find "bytes free" } )[2]; $free =~ s/\D//g;

    But that is Perl 5. I don't know if Perl 4 even provides a way to make a system call to Windows...

      bytes free
      Aren't MS Windows localized, i.e. this would work only for English users?
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Yup, you're right.

        Here's an updated kludge:

        my $free = ( split "\n", qx{ dir } )[-1]; $free = ( split ' ', $free )[2]; $free =~ s/\D//g; print $free;

        Works for at least French and English...