[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting folder size


That is ls -l

-rw-rw-r-- 2 brian brian 112 Mar 12 13:01 newname

On 3/12/24 13:55, Brian G wrote:


On 3/12/24 13:25, Bruce Steers wrote:



On Tue, 12 Mar 2024 at 19:36, Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> wrote:

    Le 12/03/2024 à 20:17, Bruce Steers a écrit :
    > I made a function to get a folder size but it differs to du
    command.
    >
    > I've tried many different things and have no clue as to why i
    am only
    > getting partly matched results.
    > I'm missing something along the line.
    >
    > My routine is simply this...
    >
    > Public Sub DirSize(Folder As String) As Long
    >
    >    Inc iCount
    >
    >    Dim iSize As Long
    >    With Stat(Folder)
    >      iSize += .Size
    >      If .Type = gb.Link Then Return ' do not compute if a link
    >    End With
    >
    >    For Each sItem As String In Dir(Folder)
    >      With Stat(Folder &/ sItem)
    >        If .Type = gb.Directory Then
    >          iSize += DirSize(Folder &/ sItem)
    >        Else
    >          iSize += .Size
    >        Endif
    >      End With
    >    Next
    >    Print iCount, iSize; "\r";
    >
    >    Return iSize
    >
    > End
    >
    > checking most folders gives a match to "du -sb" command but
    some do not.
    >
    > /home/bonus/.local/share
    > 130117  4959360696
    > 4959360696      (mine)
    > 4327428432  : out by 631932264 (du -sb)
    >
    > /home/bonus/.config
    > 498     1367011275
    > 1367011275      (mine)
    > 1367011275  : MATCH (du -sb)
    >
    > Like i say "most" folders are giving a match but some do not.
    >
    > Is my code at fault? is the du command wrong?
    >
    > Does anyone have some well written directory size calculator code?
    > Attached is a test prog with the function
    >
    > Respects and thanks in advance
    > BruceS
    >

    I guess symbolic links are not counted the same way...

-- Benoît Minisini.


I've tried handling for links in various ways.

my figure seems higher than du , do you think maybe du gives 0 bytes for links and Stat().Size gives size of the link file or something?

I guess what i want to know is what would be the most "accurate" size ?

Does anyone know of any other folder size commands i can compare with other than du?

Respects
BruceS

du counts soft links

but not

ln /home/brian/testdirectory/.a newname

hard links

say .a is 112 bytes,

our stat does not return link type but it looks like the real thing, and we count 112 bytes

du seems to see it as a real link and does not count it.... it seems

even ls does not show a hard link as a links..

--
~~~~ Brian

--
~~~~ Brian

Attachment: OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


References:
getting folder sizeBruce Steers <bsteers4@xxxxxxxxx>
Re: getting folder sizeBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: getting folder sizeBruce Steers <bsteers4@xxxxxxxxx>
Re: getting folder sizeBrian G <brian@xxxxxxxxxxxxxxxx>