Page 1 of 1
know the size of folder
Posted: Mon Jun 16, 2003 11:01 am
by ADN
Hi,
How to know the size of folder as that FileSize(NomFichier$) ?
sorry for my english
Thank
Posted: Mon Jun 16, 2003 3:53 pm
by freak
You have to add up the sizes of all files inside the directory.
The easiest way is a recursive procedure call like this one:
Code: Select all
Procedure.l DirectorySize(ID.l, Directory.s)
Protected Size.l
If ExamineDirectory(ID, Directory, "*.*")
Repeat
Entry.l = NextDirectoryEntry()
If Entry = 1
Size + DirectoryEntrySize()
ElseIf Entry = 2
Name.s = DirectoryEntryName()
If Name <> ".." And Name <> "."
Size + DirectorySize(ID+1, Directory+Name+"\")
UseDirectory(ID)
EndIf
EndIf
Until Entry = 0
EndIf
ProcedureReturn Size
EndProcedure
; Use 0 as ID, it is only needed for the recursive calls
Debug DirectorySize(0, "C:\WINNT\")
Debug DirectorySize(0, "C:\Temp\")
Timo
Posted: Mon Jun 16, 2003 10:15 pm
by PB
> The easiest way is a recursive procedure call
But be aware that if you have many big files then the total size may be
reported incorrectly due to limitations in PureBasic... I had to remove such
a procedure from one of my apps, and am waiting for big number support
in PureBasic before putting it back in.