Re: Directory info?
- Posted by just_me Sep 21, 2008
- 1080 views
Again:
On Windows:
include machine.e include dll.e include get.e constant SECTORS_PER_CLUSTER = 1, BYTES_PER_SECTOR = 2, NUMBER_OF_FREE_CLUSTERS = 3, TOTAL_NUMBER_OF_CLUSTERS = 4, TOTAL = 1, USED = 2, AVAILABLE = 3, KERNEL32 = open_dll("kernel32.dll"), xGetDiskFreeSpaceA = define_c_func(KERNEL32, "GetDiskFreeSpaceA", {C_CHAR, C_POINTER, C_POINTER, C_POINTER, C_POINTER}, C_INT) sequence sDiskSpace integer void function GetDiskFreeSpaceA(object xPath) sequence sDiskSpace atom aPath atom aSectorsPerCluster, aBytesPerSector, aNumberOfFreeClusters, aTotalNumberOfClusters sDiskSpace = {0, 0, 0, 0} if sequence(xPath) then aPath = allocate_string(xPath) else aPath = NULL end if aSectorsPerCluster = allocate(4) aBytesPerSector = allocate(4) aNumberOfFreeClusters = allocate(4) aTotalNumberOfClusters = allocate(4) if c_func(xGetDiskFreeSpaceA, {aPath, aSectorsPerCluster, aBytesPerSector, aNumberOfFreeClusters, aTotalNumberOfClusters}) then sDiskSpace[SECTORS_PER_CLUSTER] = peek4s(aSectorsPerCluster) sDiskSpace[BYTES_PER_SECTOR] = peek4s(aBytesPerSector) sDiskSpace[NUMBER_OF_FREE_CLUSTERS] = peek4s(aNumberOfFreeClusters) sDiskSpace[TOTAL_NUMBER_OF_CLUSTERS] = peek4s(aTotalNumberOfClusters) end if if sequence(xPath) then free(aPath) end if free(aSectorsPerCluster) free(aBytesPerSector) free(aNumberOfFreeClusters) free(aTotalNumberOfClusters) return sDiskSpace end function function GetDiskSpaceInBytes(object xPath) sequence sBytes, sTmpBytes sBytes = {0, 0, 0} sTmpBytes = GetDiskFreeSpaceA(xPath) sBytes[TOTAL] = sTmpBytes[BYTES_PER_SECTOR] * sTmpBytes[SECTORS_PER_CLUSTER] * sTmpBytes[TOTAL_NUMBER_OF_CLUSTERS] sBytes[AVAILABLE] = sTmpBytes[BYTES_PER_SECTOR] * sTmpBytes[SECTORS_PER_CLUSTER] * sTmpBytes[NUMBER_OF_FREE_CLUSTERS] sBytes[USED] = sBytes[TOTAL] - sBytes[AVAILABLE] return sBytes end function sDiskSpace = GetDiskSpaceInBytes("C:") printf(1, "Total: %d\nUsed: %d\nAvailable: %d", {sDiskSpace[TOTAL], sDiskSpace[USED], sDiskSpace[AVAILABLE]}) void = wait_key()
JG