Restored from previous forum. Originally posted by nbarbier.
Hello,
Could someone help me to get the size of a directory (including subdirectories)?
Thanks for your help.
Nicolas
Size of a directory (recursive)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by wichtel.
OpenConsole()
Procedure olistdir(odir.s,orek)
Shared ototal
ofile.s
opath.s
opath=odir
onext=ExamineDirectory(orek,odir,"*.*")
While onext
onext=NextDirectoryEntry()
ofile=DirectoryEntryName()
Select onext
Case 2
Select ofile
Case "."
Case ".."
Default
; PrintN("DIR: ["+opath+"\"+ofile+"]")
olistdir(opath+"\"+ofile,orek + 1)
UseDirectory(orek)
EndSelect
Case 1
; PrintN(Space(orek)+ofile)
ototal=ototal+FileSize(opath+"\"+ofile)
EndSelect
Wend
EndProcedure
Global ototal.l
oparam.s
oparam=ProgramParameter()
If oparam = "" : oparam="." : EndIf
olistdir(oparam,0)
ototal=ototal/1024
PrintN ("Size: "+Str(ototal)+" KB")
a$=Input()
CloseConsole()
----------------------------
This code goes recursive down a directory given as a command line parameter and prints the total size in KB.
Hope this helps
Michael
OpenConsole()
Procedure olistdir(odir.s,orek)
Shared ototal
ofile.s
opath.s
opath=odir
onext=ExamineDirectory(orek,odir,"*.*")
While onext
onext=NextDirectoryEntry()
ofile=DirectoryEntryName()
Select onext
Case 2
Select ofile
Case "."
Case ".."
Default
; PrintN("DIR: ["+opath+"\"+ofile+"]")
olistdir(opath+"\"+ofile,orek + 1)
UseDirectory(orek)
EndSelect
Case 1
; PrintN(Space(orek)+ofile)
ototal=ototal+FileSize(opath+"\"+ofile)
EndSelect
Wend
EndProcedure
Global ototal.l
oparam.s
oparam=ProgramParameter()
If oparam = "" : oparam="." : EndIf
olistdir(oparam,0)
ototal=ototal/1024
PrintN ("Size: "+Str(ototal)+" KB")
a$=Input()
CloseConsole()
----------------------------
This code goes recursive down a directory given as a command line parameter and prints the total size in KB.
Hope this helps
Michael
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm