Page 1 of 1

Get the size of a directory

Posted: Tue Jul 27, 2021 2:50 pm
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

Re: Get the size of a directory

Posted: Tue Jul 27, 2021 8:54 pm
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

Re: Get the size of a directory

Posted: Wed Jul 28, 2021 10:24 pm
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…