Madhan
Madhan

Reputation: 1321

How to find disk space using perl in Windows machine?

I need to get the free disk space, total disk space in windows machine using perl.

For an example,

use strict;
my $curr_drive="c:\";

From the above code, I want to get the c:\ drive free space and total space. I have tried with Filesys::DiskSpace module. But I dont how to proceed the module for windows. Please share your solutions.

Thanks

Upvotes: 5

Views: 6386

Answers (2)

macduff
macduff

Reputation: 4685

I believe CPAN has your answer: DriveInfo

Upvotes: 2

Stamm
Stamm

Reputation: 967

The module Filesys::DiskSpace is unsupported on Windows. You have to use Win32::DriveInfo.

Try the following:

use strict;
use warnings;

use Win32::DriveInfo;

my (undef, undef, undef, undef, undef, $total, $free) =
    Win32::DriveInfo::DriveSpace('c');

Upvotes: 5

Related Questions