By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

Format a number to its Byte Size

Converts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.


TCC  23.00.28 x64   Windows 7 [Version 6.1.7601]

function StrFormatByteSize=`%@winapi[shlwapi.dll,StrFormatByteSize,%1,BUFFER,256]`

echo %@StrFormatByteSize[1000]
1000 bytes

echo %@StrFormatByteSize[1023]
1023 bytes

echo %@StrFormatByteSize[1024]
1.00 KB

echo %@StrFormatByteSize[10240]
10.0 KB

echo %@StrFormatByteSize[102400]
100 KB

echo %@StrFormatByteSize[1024000]
0.97 MB

echo %@StrFormatByteSize[2400000000]
2.23 GB

Hi Charles;

I tried this with TCC 18.00.18 on Windows 7, with no success. Since it's the same shlwapi.dll, it should not be dependent on the version of TCC.

What I get is:

TCC  18.00.18   Windows 7 [Version 6.1.7601]

function StrFormatByteSize=`%@winapi[shlwapi.dll,StrFormatByteSize,%1,BUFFER,256]`

echo %@StrFormatByteSize[1000]
TCC: (Sys) The operation completed successfully.

Attempting this directly, not through a function, I see the same:

echo %@winapi[shlwapi.dll, StrFormatByteSize, 1000, BUFFER, 256]

TCC: (Sys) The operation completed successfully.

Is there some other dependency that you could think of why this would not work?
Which version of shlwapi.dll do you have on your system? I have...


More info at Shell and Shlwapi DLL Versions

Hi Joe;

Thanks for the link. I admit I'm not familiar with shlwapi.dll. I did some reading yesterday, but I didn't see anything obvious that would explain why it didn't work.

I posted yesterday from my work PC, which I can't check that version now; I'll check it later today.

On my two home PCs, my Win10 box only has TCC/LE 14, which doesn't have the winapi function, so I can't test that, but my Win7 machine shows 6.1.7601.17514. I checked, and there are four instances of the dll (C:\Windows\System32, C:\Windows\SysWOW64, and two in the winsxs directories), but all four are at the same patch level.

For whatever it's worth, the SHELL32.dll is 6.1.7601.24234.

The interesting thing is that shell32.dll is dated 2018-08-13, while shlwapi.dll is 2010-11-20, almost 8 years old. I've got a security update pending for November 2018, but other than that, the OS should be at the current patch level (at least according to Windows Update). And I can't imagine that for StrFormatByteSize, it matters whether it's Win7 Pro. Home, or another edition.
I tried on a Windows 7 32-bit system with TCC 23, and found that the version of shlwapi.dll is...

The following returns a different error message than what you received,

[C:\utils]function StrFormatByteSize=`%@winapi[shlwapi.dll,StrFormatByteSize,%1,BUFFER,256]`

[C:\utils]echo %@StrFormatByteSize[1000]
TCC: (Sys) The specified procedure could not be found.

This seems to work:
function StrFormatByteSize=`%@winapi[shlwapi.dll,StrFormatByteSizeA,%1,aBUFFER,256]`

Why the corresponding wide-character call doesn't work, I do not know.