Ca va etre dur si les fichiers sont dans un 8eme repertoire
Il suffit d'additionner les DirectoryEntrySize(id) qui donne la taille du fichier
Voila le programme de Falsam auquel j'ai ajouté le total des répertoires
(voir lignes avec --- Added)
Code : Tout sélectionner
; By Falsam
; https://www.purebasic.fr/french/viewtopic.php?p=130717#p130717
Enumeration
#MainForm
#StartStop
#ListFolder
#CountFiles
EndEnumeration
Global CountFiles.i
Global sizeFiles.i ; --- Added
Global Chemin$ = PathRequester("Répertoire a scanner", GetUserDirectory(#PB_Directory_Desktop))
;Parcourir un dossier (Fonction recurssive by Flype il me semble)
Procedure.s ParseDirectory(folder.s, id.l = 0)
If Right(folder, 1) <> "\"
folder + "\"
EndIf
If ExamineDirectory(id, folder, "*.*")
While NextDirectoryEntry(id) And GetGadgetData(#StartStop)=#True
If DirectoryEntryName(id) <> "." And DirectoryEntryName(id) <> ".."
AddGadgetItem(#ListFolder,-1, folder +Chr(10)+DirectoryEntryName(id))
countFiles+1
sizeFiles + DirectoryEntrySize(id) ; --- Added
; SetGadgetText(#CountFiles, Str(CountFiles))
; --- Added
SetGadgetText(#CountFiles, Str(CountFiles) + " Total: " + FormatNumber(sizeFiles/1024, 2) + " ko")
If DirectoryEntryType(id) = #PB_DirectoryEntry_Directory
ParseDirectory(folder + DirectoryEntryName(id), id + 1)
EndIf
EndIf
Wend
FinishDirectory(id)
EndIf
EndProcedure
Procedure StartThread(*Value)
ClearGadgetItems(#ListFolder)
CountFiles=0
ParseDirectory(Chemin$)
While GetGadgetData(#StartStop)=#True
Wend
EndProcedure
Procedure MainFormShow()
OpenWindow(#MainForm,0,0,800,600,"Lecture d'un dossier(Thread)",#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)
TextGadget(#PB_Any, 10, 10, 50, 20, "Fichier(s)")
TextGadget(#CountFiles, 100, 10, 300, 20, "0") ; --- Added 30 -> 300
ListIconGadget(#ListFolder, 10, 30, 780,530, "Dossier", 380)
AddGadgetColumn(#ListFolder, 1, "Fichier",390)
ButtonGadget(#StartStop, 10, 570, 780, 20, "Start/Stop")
EndProcedure
MainFormShow()
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #StartStop
If GetGadgetData(#StartStop)=#False
SetGadgetData(#StartStop, #True) ;Indiquer au bouton qu'il est actif
CreateThread(@StartThread(), 0)
Else
SetGadgetData(#StartStop, #False)
EndIf
EndSelect
Case #PB_Event_SizeWindow
WWidth=WindowWidth(#MainForm)
Wheight=WindowHeight(#MainForm)
ResizeGadget(#ListFolder, #PB_Ignore, #PB_Ignore , WWidth-10, Wheight-75)
ResizeGadget(#StartStop, (WWidth/2)-35, Wheight-30 , #PB_Ignore, #PB_Ignore)
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
