[Gambas-user] Size of a directory

Rolf-Werner Eilert rwe-sse at osnanet.de
Fri Sep 21 11:52:30 CEST 2018


Am 21.09.2018 um 11:26 schrieb Benoît Minisini:
> Le 21/09/2018 à 10:54, Hans Lehmann a écrit :
>> Hello,
>>
>> how do I determine the size (ilDirSize As Long) of a directory using 
>> Gambas?
>>
>> With kind regards
>>
>> Hans
>>
>> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>>
> 
> You can't, because on Unix there is no system call to get the size of a 
> directory. And I never understood the reason why they didn't implement 
> that.
> 
> You have to browse the directory, and add the size of each file one by 
> one. Very slow...
> 

The reason is, what do want to know: only the size of the directory 
itself, or recursively all subdirectories too, and do you want files 
from links being included or excluded, and if so, only softlinks or 
hardlinks, and do you want a size in bytes or clusters...???

A ready-made function by the filesystem would not do anything else than 
a function you code for yourself in, say, C, and it could not be any 
faster. And it would have to cope with all exceptions and special 
wishes, so a decent one made for yourself would be almost faster anyway.

As far as I heard, the most advanced file systems like Btrfs (though I 
don't like it) offer such fancies. From Gambas this would mean to shell 
out and call the commandline function for it. Whereas - when we speak of 
Btrfs - the size left on the media is only a rough guess, so they 
recommend to keep at least 20 % as a security buffer. You will know why 
once you crossed the limit...

But when you stay whithin one directory and leave out any linked files 
and do not go recursive, then it can be rather fast. I know that from 
midnight commander.

Regards
Rolf


More information about the User mailing list