Difference In File Size Calculations

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Difference In File Size Calculations

Post by RNIB » Thu Oct 31, 2024 4:26 pm

Where I work we create audio books in a format called DAISY and this involves checking the books in a DAISY validator which runs hundreds of different checks to make sure the book conforms to the DAISY standard. One of those checks is that it calculates the size of the book in Kilobytes and checks that this matches what has been entered into the metadata.

I'm trying to create a macro that also calculates the size of the book. Each book consists of varying amounts of .SMIL, .MP3 and .HTML files.

This is some trial code I've been working on:

Code: Select all

Let>Path=E:\Data3\Original Mass Ingestest With Links\708310

//GetFileList>%Path%\*.*,strFiles,;
//GoTo>Skip

GetFileList>%Path%\*.smil,Files1,;
GetFileList>%Path%\*.mp3,Files2,;
GetFileList>%Path%\*.html,Files3,;
Let>strFiles=%Files1%+%Files2%+%Files3%

Label>Skip
Let>y=0
Let>ByteSize=0
Repeat>y
Let>y=y+1
Separate>strFiles,;,strNames
ExtractFileName>strNames_%y%,strFileName
FileSize>%Path%\%strFileName%,strFileSize
//SetRoundMode>3
Let>strFileSize={Round(%strFileSize%)}
If>ByteSize=0
Let>ByteSize=strFileSize
Else
Let>ByteSize=ByteSize+strFileSize
endif
Until>y=strNames_Count
Let>kByte={Round(%ByteSize%/1024)}
MessageModal>Size of book = %kByte%KB
If I run the DAISY validator on this folder, it says that the size of the book is 450130KB

If I run the code as presented above, it calculates it as 449868KB

If I uncomment the two lines at the start so that it counts all files instead of just .smil, .mp3, .html (even though the folder only contains these file types), it calculates it as 450129KB. Just 1KB out from what the validator says it should be.

There are no hidden files in the folder as far as I can tell.

What am I doing wrong? I can't work out why these two different methods would produce different results and why neither exactly matches that of the validator.

It's also worth noting that it's not consistent either in that sometimes if I run it on other folders, the second method calculates the same number as that of the DAISY Validator but never is the first method correct. I've tried using different rounding modes but that made no difference that was consistent on all folders.

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Difference In File Size Calculations

Post by RNIB » Thu Oct 31, 2024 5:22 pm

Okay, I think I've worked out how to get a correct calculation when it counts the file size of ALL files. The help file says that the default mode of Round is to round to the nearest value. However it appears that I have to specifically set the round mode to 0 to make this work.

However, there is still the issue that if the macro just counts the size of .SMIL, .MP3 and .HTML files it is wildly inaccurate and yet if I manually select the files in windows explorer and get the combined properties, this does come up with the correct size. So for some reason only the macro is getting it wrong but I can't work out why.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Difference In File Size Calculations

Post by JRL » Thu Oct 31, 2024 6:02 pm

Your Let>strFiles=%Files1%+%Files2%+%Files3% line is adding a plus sign to the text. try rewriting it to:

Code: Select all

Let>strFiles=%Files1%;%Files2%;%Files3%

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Difference In File Size Calculations

Post by RNIB » Fri Nov 01, 2024 12:09 pm

Ahh, thank you. That combined with setting rounding mode to 0 seems to have done the trick

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts