Re: [WIN] drive space used != total file space used; whynot?

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
From: "Dan Moyer" <DANIELMOYER at prodigy.net>


> 
> On Win98 2nd ed, if I right-click on all top-level directories/folders on a
> drive, select "properties", and record the number of bytes USED for each
> directory(not just the sum of the size of the files in them), and then sum
> all directories, and then do the same "properties" query for the DRIVE
> itself, the sums for all directories does NOT equal the "used space" in
> bytes for the drive.  Can anyone tell me why?
> 
> I was making a utility to show all directories in descending order of space
> used on the drive for each, and it finally works, except the sum of the
> (correctly reported) sizes of all the directories doesn't equal the
> "properties" reported size of the drive itself.
> 
> Dan Moyer


Hey Dan,

On Windows 95 OSR2 and later you can use this to check the drive
space.

global function GetDiskFreeSpace(sequence drive)
    atom lpDirectoryName,lpFreeBytesAvailable,lpTotalNumberOfBytes,
  lpTotalNumberOfFreeBytes,bool
    sequence info

    lpDirectoryName=allocate_string(drive)
    lpFreeBytesAvailable=allocate(8)
    lpTotalNumberOfBytes =allocate(8)
    lpTotalNumberOfFreeBytes=allocate(8)

    bool=c_func(xGetDiskFreeSpaceEx,
  {lpDirectoryName,
  lpFreeBytesAvailable,
  lpTotalNumberOfBytes ,
  lpTotalNumberOfFreeBytes})

    info={
   peek4u(lpFreeBytesAvailable+4)*power(2,32)+peek4u(lpFreeBytesAvailable),
   peek4u(lpTotalNumberOfBytes +4)*power(2,32)+peek4u(lpTotalNumberOfBytes ),
peek4u(lpTotalNumberOfFreeBytes+4)*power(2,32)+peek4u(lpTotalNumberOfFreeBytes)
  }

    free(lpDirectoryName)
    free(lpFreeBytesAvailable)
    free(lpTotalNumberOfBytes )
    free(lpTotalNumberOfFreeBytes)
    
    return info
end function

or on Window 95 OSR-2 and below you can use this which doesnt correctly return
volume sizes that are greater than 2GB

function GetDiskFreeSpace(sequence drive)
    atom lpPathName,lpSectorsPerCluster,lpBytesPerSector,
  lpNumberOfFreeClusters,lpTotalNumberOfClusters,bool
    sequence info

    lpPathName=allocate_string2(drive)
    lpSectorsPerCluster=allocate(4)
    lpBytesPerSector=allocate(4)
    lpNumberOfFreeClusters=allocate(4)
    lpTotalNumberOfClusters=allocate(4)

    bool=c_func(hGetDiskFreeSpace,
  {lpPathName,
  lpSectorsPerCluster,
  lpBytesPerSector,
  lpNumberOfFreeClusters,
  lpTotalNumberOfClusters})

    info={
   bool,
   peek4u(lpSectorsPerCluster),
   peek4u(lpBytesPerSector),
   peek4u(lpNumberOfFreeClusters),
   peek4u(lpTotalNumberOfClusters)
  }

    --warning:
    --this function shows bytes up to 2gig drive limit,
    --but thats good enough for most aps needing to know
    --if there is free space available.

    free(lpPathName)
    free(lpSectorsPerCluster)
    free(lpBytesPerSector)
    free(lpNumberOfFreeClusters)
    free(lpTotalNumberOfClusters)
    return info
end function

I would use the first one because I dont think many people are still
using Win95 OSR-2 or lower.

Hope this help's.

Euman
euman at bellsouth.net

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu