By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,159 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,159 IT Pros & Developers. It's quick & easy.

how to check windows disk space using perl

P: 4
Hello All,

I need to find disk space on one of my drives in windows machine using perl. But, I cant seem to find windows command that I can script.

I have performed similar task for unix machine using system call and then parsing the data obtained.

system("df -k");

Does anyone know any similar command for windows?

Thanks.
Jan 21 '08 #1
Share this Question
Share on Google+
6 Replies


eWish
Expert 100+
P: 971
Welcome to TSDN!

Have a look at Win32::DriveInfo at CPAN.

--Kevin
Jan 21 '08 #2

P: 4
Thank You Kevin for your quick reply. But, I am relatively new to perl and cant seem to install this perl module.

I get the following error when I run the script containing this module
Can't locate Win32/API/Type.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/
lib .) at C:/Perl/site/lib/Win32/API.pm line 31.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Win32/API.pm line 31.
Compilation failed in require at C:/Perl/site/lib/Win32/DriveInfo.pm line 5.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Win32/DriveInfo.pm line 5.

Compilation failed in require at C:\find_drive_space.pl line 3.
BEGIN failed--compilation aborted at C:\find_drive_space.pl line 3.

code:

#!/usr/bin/perl

use Win32::DriveInfo;

($SectorsPerCluster,
$BytesPerSector,
$NumberOfFreeClusters,
$TotalNumberOfClusters,
$FreeBytesAvailableToCaller,
$TotalNumberOfBytes,
$TotalNumberOfFreeBytes) = Win32::DriveInfo::DriveSpace('c');

$TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace('c:'))[6];



print"Free disk space available in C drive is $TotalNumberOfFreeBytes\n";


I seem to be very close. Thanks once again.
Jan 21 '08 #3

eWish
Expert 100+
P: 971
I am assuming that you are on a Windows machine. If you are using ActiveState perl then you can use the PPM utility.

--Kevin
Jan 22 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
at the DOS prompt type

dir /?

and you should get a list of the dir command and options
Jan 22 '08 #5

P: 4
Thanks Moderator and Kevin. I am going to try pm as I have spent some time on it. The dos prompt option looks good too and would try it.

Thanks.
Jan 22 '08 #6

KevinADC
Expert 2.5K+
P: 4,059
It's an old module, so I would make sure it's spitting out good numbers before using it for anything important.
Jan 23 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.