Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

disk usage in windows

by kitsonrp (Novice)
on Jul 21, 2003 at 09:07 UTC ( [id://276193]=perlquestion: print w/replies, xml ) Need Help??

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

hi,

Does anyone know of a way to find disk partition infor mation for windows. I need an efficient way to find:

1. total space on drive c:

2. Amount used on drive c:

Due to the overhead on the system I don't want to total each file

Thanks.

Replies are listed 'Best First'.
Re: disk usage in windows
by edan (Curate) on Jul 21, 2003 at 09:13 UTC

    I have no idea, but a quick CPAN search for win32 disk space yielded the following module: Win32::DriveInfo.

    You might want to look through Win32::API, since I'm pretty sure there is a Win32 API call to get that info...

    Update: Yeah, its GetDiskFreeSpace or GetDiskFreeSpaceEx

    --
    3dan
      Thanks for the info, that will work well.
Re: disk usage in windows
by jsprat (Curate) on Jul 21, 2003 at 18:26 UTC
    Use the FileSystemObject, a wrapper around the API. It runs almost instantaneously. It's installed if you've got Windows Script Host installed. Here's an example:

    #!perl use warnings; use strict; use Win32::OLE; my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject'); my $d = $fs->GetDrive('c:'); print $d->{TotalSize}, " total\n"; print $d->{FreeSpace}, " free\n"; print $d->{AvailableSpace}, " available\n"; print $d->{TotalSize} - $d->{FreeSpace}, " used\n"; __END__ Output on my system: 4446814208 total 2482372608 free 2482372608 available 1964441600 used

      Thanks jsprat, it saves me a lot of run-time!

      I would ++ (but I spent them all)

Re: disk usage in windows
by chimni (Pilgrim) on Jul 21, 2003 at 10:39 UTC
    Hi i suggest you dont use perl for this. Nobody kill me. Just that inthis case for windows 2000 and XP (not NT) WMI windows managements instrumentation is the best bet. Try a search on WMI
    regards
    chimni

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found