checking free disk space

Pieter Claerhout Pieter_Claerhout at CreoScitex.com
Wed Jan 17 03:49:29 EST 2001


Here's how you can do this on Windows:


#### START OF CODE ####
import string
import win32api
import win32file

def PrintSpaceReport(drive):
    sectorsPerCluster, bytesPerSector, numFreeClusters, totalNumClusters =
win32file.GetDiskFreeSpace(drive + ":\\")
    sectorsPerCluster = long(sectorsPerCluster)
    bytesPerSector = long(bytesPerSector)
    numFreeClusters = long(numFreeClusters)
    totalNumClusters = long(totalNumClusters)

    print
    print "Drive:     ", drive + ":\\"
    print "FreeSpace: ", (numFreeClusters * sectorsPerCluster *
bytesPerSector) / (1024 * 1024), "MB"
    print "TotalSpace:", (totalNumClusters * sectorsPerCluster *
bytesPerSector) / (1024 * 1024), "MB"
    print "UsedSpace: ", ((totalNumClusters - numFreeClusters ) *
sectorsPerCluster * bytesPerSector) / (1024 * 1024), "MB"

def main():
    AvailableDrives = []
    for i in string.split(win32api.GetLogicalDriveStrings(), '\000'):
        if win32file.GetDriveType(i) == 3: # we only need fixed drives (no
CD drives)
            AvailableDrives.append(i[:-2])
    DriveInfo = []

    print "Drive free space report"

    for drive in AvailableDrives:
        PrintSpaceReport(drive)

if __name__ == '__main__':
    main()
#### END OF CODE ###


Kind regards,


Pieter


-----Original Message-----
From: sill at localhost.kitenet.net [mailto:sill at localhost.kitenet.net]
Sent: Wednesday, January 17, 2001 2:56 AM
To: python-list at python.org
Subject: Re: checking free disk space


On Mon, 15 Jan 2001 14:23:59 +0200, Langa Kentane
<LangaK at discoveryhealth.co.za> wrote:
>Good day.
>
>I want to write a script that I can use to check the free disk space on all
>drives.  The script will be used in Linux and Wind0ze.
>
>For instance, I want to write something like:
>
>get list of mounts/drives
>for i in mount_list
>	check disk space left in %
>	if disk space is certain amout:
>		do this
>	else
>		do that
>	endif
>endrun
>
>Please can you point me in the right direction.  I posted something before
>on this list but I realised that will not work in a wind0ze environment.

On unix you can parse output of df, and on windows I'm not entirely sure
but doesn't dir command tell you how much space is left on drive? So you
can keep trying cd X:; dir; starting with C and until you run out of
drives..
You can tell if it's a cd if it's under 650mb and has no free space at all.

>
>Thanks in advance.
>
>__________________________________________________________
>Langa Kentane		| TEL: (011) 290 3218
>Security Administrator	| Cell: 082 606 1515
>DISCOVERY HEALTH		| http://www.discoveryhealth.co.za
>__________________________________________________________________
>
>


-- 

	Andrei
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list