Size of a directory (recursive)

Windows specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

Welcome to the forum both of you.
also try doing a search with the words "directory subdirectories"
That will give you some ideas.
Post Reply