News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to show disk space in byte?

Started by elmo, November 12, 2010, 04:20:25 AM

Previous topic - Next topic

elmo

I use the following code:

   invoke GetDiskFreeSpaceEx, CTXT("C:\"),addr freeSpace,addr totalSpace,0
   invoke StrFormatByteSize64, totalSpace, totalSpace+4, ADDR totalbuffer, SIZEOF totalbuffer
   invoke StrFormatByteSize64, freeSpace, freeSpace+4, ADDR freebuffer, SIZEOF freebuffer
   invoke MessageBox, NULL,addr freebuffer,CTXT("C:\ free space"), MB_OK
   invoke MessageBox, NULL,addr totalbuffer,CTXT("C:\ total space"), MB_OK   
       ;invoke MessageBox, NULL,addr usedbuffer,CTXT("C:\ used space"), MB_OK   ;WHERE USED BUFFER=TOTALBUFFER-FREEBUFFER


in my PC, it show:
Free space=5.96GB
Total space=18.6GB

I must get value of FreeSpace (5.96) then I multiply it with  (1024*1024*1024) to show it in Byte.
But how to get (5.96) from (5.96 GB) ?
In here, I use StrFormatByteSize64. can we use other function?
be the king of accounting programmer world!

MichaelW

If I understand what you are trying to do, the GetDiskFreeSpaceEx function returns the values in bytes, so one method would be to use 64-bit integers and the CRT sprintf function to convert the values to formatted strings.

;=========================================================================
    include \masm32\include\masm32rt.inc
;=========================================================================
    .data
      dqFreeBytes   dq 0
      dqTotalBytes  dq 0
      szFreeBytes   db 50 dup(0)
      szTotalBytes  db 50 dup(0)
    .code
;=========================================================================
start:
;=========================================================================

    invoke GetDiskFreeSpaceEx, chr$("c:"),
                               ADDR dqFreeBytes,
                               ADDR dqTotalBytes,
                               NULL

    ;invoke crt_printf,cfm$("free bytes:\t%I64d\n"), dqFreeBytes
    ;invoke crt_printf,cfm$("total bytes:\t%I64d\n\n"), dqTotalBytes

    invoke crt_sprintf, ADDR szFreeBytes,
                        cfm$("free bytes:\t%I64d"),
                        dqFreeBytes

    invoke crt_sprintf, ADDR szTotalBytes,
                        cfm$("total bytes:\t%I64d"),
                        dqTotalBytes

    print ADDR szFreeBytes,13,10
    print ADDR szTotalBytes,13,10,13,10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

elmo

Thank you MichaelW.
But from my previous code, in my PC, it show byte value in GB because I use "StrFormatByteSize64".

Quote from: durahan on November 12, 2010, 04:20:25 AM
in my PC, it show:
Free space=5.96GB
Total space=18.6GB

Can I use other function? So, I can show it in Byte. How?
so, the result will be:
Free space = 5.96*1024*1024*1024 Bytes
Total space = 18.6*1024*1024*1024 Bytes
be the king of accounting programmer world!

MichaelW

The code I posted shows the values in bytes, as returned by GetDiskFreeSpaceEx. Values in byte units are exact, where the values from StrFormatByteSize64 in other units are rounded to some small number of digits, so they are likely to be approximations. For example, on my system the exact total bytes is 20,002,275,328, StrFormatByteSize64 shows 18.6 GB, and:

18.6*1024*1024*1024 = 19,971,597,926
eschew obfuscation