Question Show size on disk as two digit MB's.

Apr 29, 2019
9
0
10
Good afternoon,

I have been struggling with this and would appreciate some help please!

I have two compressed [zipped] folders on the desktop that get generated via a batch file. I would like a script [I know that I can right-click them and select properties to find out the information but I don't want to do it with a script] to give me the actual Size: and the Size on disk: as megabytes. I found some code on the Internet and have tried to adapt it. These are my questions please...

[1] In the script below it is for a desktop .log file [for testing purposes]. How can I change this to the compressed [zipped] folder name, also on the desktop?
[2] For the actual Size: I can't get it converted to megabytes as two decimal places.
[3] I have converted the bytes to megabytes for Size on disk: but how can I get it to show as two decimal places?

Here is the code...

Code:
@echo off

setlocal

for %%I in (CBS.log) do (
    set "fs=%%~zI"
    for /f %%J in (
        'wmic volume where "driveletter='%%~dI'" get blocksize /value'
    ) do 2>nul set /a %%J
)

echo Size [Bytes]:         %fs%
echo Size [MB's]:          %fs%

set /a ondisk =  ((fs-1)/blocksize+1) * blocksize
set /a ondisk1 = ((fs-1)/blocksize+1) * blocksize / 1024 / 1024

echo.
echo Size on disk [Bytes]: %ondisk%
echo Size on disk [MB's]:  %ondisk1%
echo.

pause

Any help will be greatly appreciated.

Thanks in advance.
 
Apr 29, 2019
9
0
10
Consider using Powershell.

Reference starter link:

https://docs.microsoft.com/en-us/windows/desktop/fileio/obtaining-the-size-of-a-compressed-file

You can easily google for more information using words and phrases such as "powershell zip file size".

For example the following link from within this Forum:

https://forums.tomshardware.com/thr...zip-files-without-decompressing-them.3327444/

Thank you very much for the reply Ralston18, it is appreciated.

I have looked at the links you kindly provided, than you for those. I really need to do this via a batch file.

I will keep Googling for an answer.
 

TRENDING THREADS