Is it possible to get Folder Size?

BlitzMax Forums/BlitzMax Programming/Is it possible to get Folder Size?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi,

Here's an interesting alternative.

Of course, you've got to keep 'poking' it, but even a multithreaded solution would required some kind of repetition.


Strict

Type TDirSize

	Method Done()
		Return _entry=_entries.length And _dirs.IsEmpty()
	End Method

	Method Update:Long()
		For Local count=1 To 2500
			While _entry=_entries.length
				If _dirs.IsEmpty() Return _size
				_dir=String( _dirs.RemoveLast() )
				_entries=LoadDir( _dir )
				_entry=0
			Wend
			Local path$=_dir+"/"+_entries[_entry]
			_entry:+1
			If FileType( path )=FILETYPE_DIR
				_dirs.AddLast path
			Else
				_size:+FileSize( path )
			EndIf
		Next
		Return _size
	End Method

	Function Create:TDirSize( dir$ )
		Assert FileType( dir )=FILETYPE_DIR
		Local t:TDirSize=New TDirSize
		t._dirs.AddLast dir
		Return t
	End Function
	
	Field _size:Long
	Field _dirs:TList=New TList
	Field _dir$,_entries$[],_entry
	
End Type

Local t:TDirSize=TDirSize.Create( "c:" )

While Not t.Done()
	Print t.Update()
Wend

Print "Done!"
End