Re: get free disk space in win32 ** Figured it out. Code inside for anyone else who wants to use it.
- Posted by ssallen Dec 20, 2009
- 1229 views
Correct Code follows:
New code:
constant kernel32 = open_dll( "kernel32.dll" ), xGetFreeSpace = define_c_func(kernel32, "GetDiskFreeSpaceExA", {C_POINTER, C_POINTER, C_POINTER, C_POINTER}, C_INT) global function get_drive_space(sequence mdir) atom strptr, ptr2, ptr3, ptr4 integer retx sequence rets strptr = allocate_string(mdir) ptr2 = allocate(8) ptr3 = allocate(8) ptr4 = allocate(8) retx = c_func(xGetFreeSpace, {strptr, ptr2, ptr3, ptr4}) if retx <= 0 then free(strptr) free(ptr2) free(ptr3) free(ptr4) return {-1, -1} end if rets = {{0, 0}, {0, 0}, {0, 0}} rets[1][1] = peek4u(ptr2) rets[1][2] = peek4u(ptr2+4) rets[2][1] = peek4u(ptr3) rets[2][2] = peek4u(ptr3+4) rets[3][1] = peek4u(ptr4) rets[3][2] = peek4u(ptr4+4) free(strptr) free(ptr2) free(ptr3) free(ptr4) return rets end function
and then...
sequence vals vals = get_drive_space(data_dir) if length(vals) < 3 then setText(txt2, "BAD DISK SPACE CHECK!") else setText(txt2, sprintf("Disk space is: %d", ((vals[3][2] * #100000000) + vals[3][1]))) end if
((vals[1][2] * #100000000) + vals[1][1])) - total number of free bytes on a disk that are available to the user who is associated with the calling thread. adjusted for per-user quotas
((vals[2][2] * #100000000) + vals[2][1])) - total number of bytes on a disk that are available to the user who is associated with the calling thread. ajusted for per-user quotas
((vals[3][2] * #100000000) + vals[3][1])) - total number of free bytes on a disk. DOES NOT adjust for per-user quotas.
Thanks to Larry! You Rock!
Steve A.