Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

[MBS] Matching File Size as Shown in Finder (MBS Xojo Plugin Mailinglist archive)

Back to the thread list
Previous thread: [MBS] Alias info and GetRelative compatibles?
Next thread: [MBS] [ANN] 13.1pr15


Re: [MBS] PortAudio bug?   -   Garth Hjelte
  [MBS] Matching File Size as Shown in Finder   -   Scott Crick
   Re: [MBS] Matching File Size as Shown in Finder   -   Christian Schmitz
   Re: [MBS] Matching File Size as Shown in Finder   -   Steve Upton
   Re: [MBS] Matching File Size as Shown in Finder   -   Tim Jones
   Re: [MBS] Matching File Size as Shown in Finder   -   Scott Crick
   Re: [MBS] Matching File Size as Shown in Finder   -   Scott Crick
   Re: [MBS] Matching File Size as Shown in Finder   -   Marnaud
   Re: [MBS] Matching File Size as Shown in Finder   -   Christian Schmitz

[MBS] Matching File Size as Shown in Finder
Date: 21.04.13 02:21 (Sat, 20 Apr 2013 20:21:50 -0500)
From: Scott Crick
I have an application where I need to be able to show the size of a file that same as how it is shown in the Finder.

I have tried a few different methods of calculating file sizes and none of them produce results that are consistent with what is displayed in the Finder.

For example, I have a PDF file that, in the Finder, shows as being "339 KB"

When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.

Is there a different function I should be using? I need to get the size as it's reported in the Finder.

I would appreciate any help on this one.

Thanks!

Sincerely,

Scott
-

Re: [MBS] Matching File Size as Shown in Finder
Date: 22.04.13 20:33 (Mon, 22 Apr 2013 21:33:16 +0200)
From: Christian Schmitz

On 22.04.2013, at 20:17, Steve Upton <<email address removed>> wrote:

>> I didn't realize there was also a FolderItem.LogicalFileTotalLengthMBS function. When I use this function I am getting the same sizes as reported by the Finder.
>
> Makes sense.
>
> The Finder will display the amount of space a file takes up on disk - including the padding to fill out the smallest block size on the volume

Well, physical size is rounded up to blocks and logical is the exact size.

Pick what you want :-)

Greetings
Christian

Re: [MBS] Matching File Size as Shown in Finder
Date: 22.04.13 19:17 (Mon, 22 Apr 2013 11:17:44 -0700)
From: Steve Upton

On Apr 21, 2013, at 5:13 PM, Scott Crick <<email address removed>> wrote:

> On Apr 20, 2013, at 8:21 PM, Scott Crick <<email address removed>> wrote:
>
>> For example, I have a PDF file that, in the Finder, shows as being "339 KB"
>>
>> When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.
>>
>> Is there a different function I should be using? I need to get the size as it's reported in the Finder.
>>
>> I would appreciate any help on this one.
>
> I think I have figured this out.
>
> I didn't realize there was also a FolderItem.LogicalFileTotalLengthMBS function. When I use this function I am getting the same sizes as reported by the Finder.

Makes sense.

The Finder will display the amount of space a file takes up on disk - including the padding to fill out the smallest block size on the volume

regards,

Steve

_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] Matching File Size as Shown in Finder
Date: 22.04.13 01:15 (Sun, 21 Apr 2013 17:15:52 -0700)
From: Tim Jones
>From what I see in my shell tests, it appears that Finder reports the "ls -leO" size divided by 1000 (for K) divided by 1000 again for M divided by 1000 again for G and then rounds up to 2 decimal places. for example,

$ ls -leO /Volumes/VD 1/OSX-10.8.iso
-rw-r--r-- 1 tjones staff - 4379291648 Feb 19 20:10 /Volumes/VD 1/OSX-10.8.iso

If you then do:

4379291648 / 1000.0 / 1000.0 / 1000.0

You get 4.379 G. Finder reports this as 4.38G

Tim

On Apr 21, 2013, at 7:27 AM, Scott Crick <<email address removed>> wrote:

>
> On Apr 21, 2013, at 12:49 AM, Christian Schmitz <<email address removed>> wrote:
>
>>
>> On 21.04.2013, at 03:21, Scott Crick <<email address removed>> wrote:
>>
>>> When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.
>>
>> FolderItem.PhysicalFileTotalLengthMBS is the size of resource fork and data fork.
>> It does not count extended attributes.
>
> Hmmm... is there another call that works better?
>
>>> Is there a different function I should be using? I need to get the size as it's reported in the Finder.
>>

_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] Matching File Size as Shown in Finder
Date: 22.04.13 01:13 (Sun, 21 Apr 2013 19:13:12 -0500)
From: Scott Crick
On Apr 20, 2013, at 8:21 PM, Scott Crick <<email address removed>> wrote:

> For example, I have a PDF file that, in the Finder, shows as being "339 KB"
>
> When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.
>
> Is there a different function I should be using? I need to get the size as it's reported in the Finder.
>
> I would appreciate any help on this one.

I think I have figured this out.

I didn't realize there was also a FolderItem.LogicalFileTotalLengthMBS function. When I use this function I am getting the same sizes as reported by the Finder.

Sincerely,

Scott
-

Re: [MBS] Matching File Size as Shown in Finder
Date: 21.04.13 15:27 (Sun, 21 Apr 2013 09:27:32 -0500)
From: Scott Crick

On Apr 21, 2013, at 12:49 AM, Christian Schmitz <<email address removed>> wrote:

>
> On 21.04.2013, at 03:21, Scott Crick <<email address removed>> wrote:
>
>> When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.
>
> FolderItem.PhysicalFileTotalLengthMBS is the size of resource fork and data fork.
> It does not count extended attributes.

Hmmm... is there another call that works better?

>> Is there a different function I should be using? I need to get the size as it's reported in the Finder.
>
>
> You could ask the Finder for file size with AppleEvents/AppleScripts.

The problem there is that I can't rely on the Finder running. I need a method that would be independent of the Finder.

Sincerely,

Scott
-

Re: [MBS] Matching File Size as Shown in Finder
Date: 21.04.13 14:42 (Sun, 21 Apr 2013 15:42:13 +0200)
From: Marnaud
Le 21 avr. 2013 à 7:49, Christian Schmitz a écrit:

> On 21.04.2013, at 03:21, Scott Crick <<email address removed>> wrote:
>
>> When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.
>
> FolderItem.PhysicalFileTotalLengthMBS is the size of resource fork and data fork.
> It does not count extended attributes.

There's no call (shell or API) to include these extended attributes?

>> Is there a different function I should be using? I need to get the size as it's reported in the Finder.
>
> You could ask the Finder for file size with AppleEvents/AppleScripts. Like this:
>
> on getSizeInBytesFromPosixPath(posixPath)
> try
> set b to (POSIX file posixPath) as string
> tell application "Finder" to return size of (b as alias)
> on error
> return 0
> end try
> end getSizeInBytesFromPosixPath

This would fail on a setup like mine, where I have replaced the Finder by Path Finder (so the Finder doesn't run).
_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] Matching File Size as Shown in Finder
Date: 21.04.13 06:49 (Sun, 21 Apr 2013 07:49:52 +0200)
From: Christian Schmitz

On 21.04.2013, at 03:21, Scott Crick <<email address removed>> wrote:

> When I use FolderItem.PhysicalFileTotalLengthMBS, the size of this file is returned as 331776 bytes. When I divide this by 1024, I get 324 KB. If I divide it by 1000, I get 331 KB. Neither of these is what the Finder is reporting—339 KB.

FolderItem.PhysicalFileTotalLengthMBS is the size of resource fork and data fork.
It does not count extended attributes.

> Is there a different function I should be using? I need to get the size as it's reported in the Finder.

You could ask the Finder for file size with AppleEvents/AppleScripts. Like this:

on getSizeInBytesFromPosixPath(posixPath)
try
set b to (POSIX file posixPath) as string
tell application "Finder" to return size of (b as alias)
on error
return 0
end try
end getSizeInBytesFromPosixPath

Greetings
Christian

-