Get the size of a directory

Find quick help here to get you started with Hollywood
Post Reply
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Get the size of a directory

Post by mrupp »

Hi there

I'm looking for an easy way to get the size of a directory. Thought there might be something like a GetDirectorySize() function, but there seems to be none.
I stumbled accross the p_TraverseDir() example on the "DirectoryItems" page and modified it like this:

Code: Select all

Function p_GetDirectorySize(d$, recursive)
	Local ret = 0
	For s$, t In DirectoryItems(d$)
		If t.type = #DOSTYPE_FILE
			ret = ret + t.size
		ElseIf recursive
			ret = ret + p_GetDirectorySize(FullPath(d$, s$), recursive)
		EndIf
	Next
	Return(ret)
EndFunction
Is that the way to do it or is there an easier way?
Maybe such a GetDirectorySize() function would be a nice addition to the DOS library for Hollywood 9.1... ;)

Cheers, Michael
plouf
Posts: 467
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Get the size of a directory

Post by plouf »

i agree about usefuless of this command

but because is posted "questions" i think currently only workaround is to use a comamndline tolle (like diruse.exe in windows) and catch its output
Christos
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Get the size of a directory

Post by airsoftsoftwair »

plouf wrote: Tue Jul 27, 2021 8:54 pm i agree about usefuless of this command

but because is posted "questions" i think currently only workaround is to use a comamndline tolle (like diruse.exe in windows) and catch its output
Um, why use an external command when you can just do it like Michael suggested?

Concerning an inbuilt function to do this: there is none but it’s easily possible to do as Michael has shown…
Post Reply