Problem with win32api function + using DLL "directly" in windows
Dave LeBlanc
whisper at oz.net
Sat Apr 14 15:44:02 EDT 2001
Mark Hammond has reported that he's added GetDiskFreeSpaceEx. Probably
in CVS.
Dave LeBlanc
On Fri, 13 Apr 2001 20:34:11 GMT, "Dublanc, David" <ddublanc at free.fr>
wrote:
>
>I use this script (that I found in the newsgroup) and the result is not
>correct. Is it possible to use Windows DLL libraries library in Python ?
>Because there is a
>GetDiskFreeSpaceEx that seems to return the good results (thanks to Chris
>Gonnerman who gives me the name of this function).
>
>David
>
>***************************
>import string,win32api,win32file
>
>def PrintSpaceReport(drive):
> sectorsPerCluster,bytesPerSector,numFreeClusters,totalNumClusters =
>win32file.GetDiskFreeSpace(drive + ":\\")
> print sectorsPerCluster, bytesPerSector,
>numFreeClusters,totalNumClusters
>
> sectorsPerCluster = long(sectorsPerCluster)
> bytesPerSector = long(bytesPerSector)
> numFreeClusters = long(numFreeClusters)
> totalNumClusters = long(totalNumClusters)
>
> print "Drive : ", drive + ":\\"
> print "Freespace : ", numFreeClusters * sectorsPerCluster *
>bytesPerSector / (1024**2), "MB"
> print "Totalspace : ", totalNumClusters * sectorsPerCluster *
>bytesPerSector / (1024**2), "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 AvailableDrives
> for drive in AvailableDrives:
> PrintSpaceReport(drive)
>
>if __name__ == '__main__':
> main()
>*******************************************
>
>"Mark Hammond" <MarkH at ActiveState.com> a écrit dans le message news:
>3AD70CBA.8050202 at ActiveState.com...
>> Dublanc, David wrote:
>>
>> > I have a problem with the fonction win32file.GetDiskFreeSpace
>>
>> >
>>
>> > The maximum number of space is : 65536 bytes. So if the hard disk
>capacity
>>
>> > is > 2 Go, the function returns a wrong result.
>>
>> >
>>
>> > Do you have solution for this problem ?
>>
>>
>> Check out the documentation in the help files - the number of bytes is
>> not returned, but 4 different values are to help you calculate it:
>>
>> "number of sectors per cluster, the number of bytes per sector, the
>> total number of free clusters on the disk and the total number of
>> clusters on the disk"
>>
>> >>> import win32file
>> >>> spc, bps, free_c, tot_c = win32file.GetDiskFreeSpace("F:\\")
>> >>> print 1L * free_c * spc * bps
>> 2477039616
>> >>>
>>
>> Note the "1L" will prevent integer overflow - this little wart should be
>> removed in a Python coming your way soon :)
>>
>> Mark.
>>
>>
>
>
More information about the Python-list
mailing list