Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Util/FolderSize
Function:
Required plugins for this example: MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/FolderSize
This example is the version from Wed, 27th Jan 2015.
Project "FolderSize.rbp"
FileTypes
Filetype special/folder
End FileTypes
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class MyThread Inherits Thread
EventHandler Sub Run() f = new DirectorySizeMBS dim StartTicks as integer = ticks OK = f.Update(ff,true,tt) TicksNeeded = ticks - StartTicks done = true End EventHandler
Property OK As Boolean
Property TicksNeeded As integer
Property done As Boolean
Property f As DirectorySizeMBS
Property ff As folderItem
Property tt As integer
End Class
Class MainWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim t as integer dim d,r as Double dim fi,fo as integer d=0 r=0 t=ticks dir1 SpecialFolder.System,d,r,fi,fo t=ticks-t pTime.text=Format(t,"0")+" ticks" pData.text=Format(d,"0")+" bytes" pRes.text=Format(r,"0")+" bytes" pTotal.text=Format(r+d,"0")+" bytes" pFiles.text=Format(fi,"0") pFolders.text=Format(fo,"0") End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim t as integer dim ld,lr,pd,pr as Double dim fi,fo as integer pd=0 pr=0 ld=0 lr=0 t=ticks dir2 SpecialFolder.System,ld,lr,pd,pr,fi,fo t=ticks-t rTime.text=Format(t,"0")+" ticks" rLData.text=Format(ld,"0")+" bytes" rLRes.text=Format(lr,"0")+" bytes" rLTotal.text=Format(lr+ld,"0")+" bytes" rPData.text=Format(pd,"0")+" bytes" rPRes.text=Format(pr,"0")+" bytes" rPTotal.text=Format(pr+pd,"0")+" bytes" rFiles.text=Format(FI,"0") rFolders.text=Format(Fo,"0") End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim tt,t as integer dim f as DirectorySizeMBS tt=val(PopupMenu1.text) t=ticks f=SpecialFolder.System.CalculateDirectorySizeMBS(true,tt) t=ticks-t uTime.text=Format(t,"0")+" ticks" if f<>Nil then uLData.text=Format(f.LogicalDataForkSize,"0")+" bytes" uLRes.text=Format(f.LogicalResourceForkSize,"0")+" bytes" uLTotal.text=Format(f.LogicalTotalSize,"0")+" bytes" uPData.text=Format(f.PhysicalDataForkSize,"0")+" bytes" uPRes.text=Format(f.PhysicalResourceForkSize,"0")+" bytes" uPTotal.text=Format(f.PhysicalTotalSize,"0")+" bytes" uFiles.text=Format(f.FilesCount,"0") uFolders.text=Format(f.FolderCount,"0") end if End EventHandler
End Control
Control GroupBox1 Inherits GroupBox
ControlInstance GroupBox1 Inherits GroupBox
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control pTime Inherits Label
ControlInstance pTime Inherits Label
End Control
Control pData Inherits Label
ControlInstance pData Inherits Label
End Control
Control pRes Inherits Label
ControlInstance pRes Inherits Label
End Control
Control pTotal Inherits Label
ControlInstance pTotal Inherits Label
End Control
Control StaticText16 Inherits Label
ControlInstance StaticText16 Inherits Label
End Control
Control pFiles Inherits Label
ControlInstance pFiles Inherits Label
End Control
Control StaticText18 Inherits Label
ControlInstance StaticText18 Inherits Label
End Control
Control pFolders Inherits Label
ControlInstance pFolders Inherits Label
End Control
Control GroupBox2 Inherits GroupBox
ControlInstance GroupBox2 Inherits GroupBox
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End Control
Control StaticText8 Inherits Label
ControlInstance StaticText8 Inherits Label
End Control
Control rTime Inherits Label
ControlInstance rTime Inherits Label
End Control
Control rLData Inherits Label
ControlInstance rLData Inherits Label
End Control
Control rLRes Inherits Label
ControlInstance rLRes Inherits Label
End Control
Control rLTotal Inherits Label
ControlInstance rLTotal Inherits Label
End Control
Control StaticText13 Inherits Label
ControlInstance StaticText13 Inherits Label
End Control
Control StaticText14 Inherits Label
ControlInstance StaticText14 Inherits Label
End Control
Control StaticText15 Inherits Label
ControlInstance StaticText15 Inherits Label
End Control
Control rPData Inherits Label
ControlInstance rPData Inherits Label
End Control
Control rPRes Inherits Label
ControlInstance rPRes Inherits Label
End Control
Control rPTotal Inherits Label
ControlInstance rPTotal Inherits Label
End Control
Control StaticText24 Inherits Label
ControlInstance StaticText24 Inherits Label
End Control
Control StaticText25 Inherits Label
ControlInstance StaticText25 Inherits Label
End Control
Control rFiles Inherits Label
ControlInstance rFiles Inherits Label
End Control
Control rFolders Inherits Label
ControlInstance rFolders Inherits Label
End Control
Control GroupBox3 Inherits GroupBox
ControlInstance GroupBox3 Inherits GroupBox
End Control
Control StaticText9 Inherits Label
ControlInstance StaticText9 Inherits Label
End Control
Control StaticText10 Inherits Label
ControlInstance StaticText10 Inherits Label
End Control
Control StaticText11 Inherits Label
ControlInstance StaticText11 Inherits Label
End Control
Control StaticText12 Inherits Label
ControlInstance StaticText12 Inherits Label
End Control
Control uTime Inherits Label
ControlInstance uTime Inherits Label
End Control
Control ulData Inherits Label
ControlInstance ulData Inherits Label
End Control
Control ulRes Inherits Label
ControlInstance ulRes Inherits Label
End Control
Control ulTotal Inherits Label
ControlInstance ulTotal Inherits Label
End Control
Control StaticText20 Inherits Label
ControlInstance StaticText20 Inherits Label
End Control
Control StaticText21 Inherits Label
ControlInstance StaticText21 Inherits Label
End Control
Control StaticText22 Inherits Label
ControlInstance StaticText22 Inherits Label
End Control
Control upData Inherits Label
ControlInstance upData Inherits Label
End Control
Control upRes Inherits Label
ControlInstance upRes Inherits Label
End Control
Control upTotal Inherits Label
ControlInstance upTotal Inherits Label
End Control
Control StaticText19 Inherits Label
ControlInstance StaticText19 Inherits Label
End Control
Control StaticText23 Inherits Label
ControlInstance StaticText23 Inherits Label
End Control
Control uFiles Inherits Label
ControlInstance uFiles Inherits Label
End Control
Control uFolders Inherits Label
ControlInstance uFolders Inherits Label
End Control
Control StaticText17 Inherits Label
ControlInstance StaticText17 Inherits Label
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control ChasingArrows1 Inherits ProgressWheel
ControlInstance ChasingArrows1 Inherits ProgressWheel
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() if cc<>nil then cc.f.cancel=true end End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action() cc=new MyThread cc.tt=val(MainWindow.PopupMenu1.text) cc.ff=SpecialFolder.System cc.run End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() if cc<>nil and cc.done then dim f as DirectorySizeMBS = cc.f MainWindow.uTime.text=Format(cc.TicksNeeded,"0")+" ticks" if cc.OK then MainWindow.uLData.text=Format(f.LogicalDataForkSize,"0")+" bytes" MainWindow.uLRes.text=Format(f.LogicalResourceForkSize,"0")+" bytes" MainWindow.uLTotal.text=Format(f.LogicalTotalSize,"0")+" bytes" MainWindow.uPData.text=Format(f.PhysicalDataForkSize,"0")+" bytes" MainWindow.uPRes.text=Format(f.PhysicalResourceForkSize,"0")+" bytes" MainWindow.uPTotal.text=Format(f.PhysicalTotalSize,"0")+" bytes" MainWindow.uFiles.text=Format(f.FilesCount,"0") MainWindow.uFolders.text=Format(f.FolderCount,"0") else cc = nil MsgBox "Error while calculating." end if if f.Cancel then cc = nil MsgBox "Canceled while calculating." end if beep cc = nil end if End EventHandler
End Control
EventHandler Sub DropObject(obj As DragItem, action As Integer) cc=new MyThread cc.ff=obj.FolderItem cc.run End EventHandler
EventHandler Sub Open() me.AcceptFileDrop "any" End EventHandler
Sub dir1(f as folderitem, byref d as double, byref r as double, byref fi as integer, byref fo as integer) dim i, c as integer dim g as FolderItem dim dd,rr as Double dim ffi,ffo as integer fo=fo+1 c=f.Count for i=1 to c g=f.TrueItem(i) if g<>nil then if g.Directory then dd=0 rr=0 ffi=0 ffo=0 dir1 g,dd,rr,ffi,ffo d=d+dd r=r+rr fi=fi+ffi fo=fo+ffo else d=d+g.Length r=r+g.ResourceForkLength fi=fi+1 end if end if next Exception End Sub
Sub dir2(f as folderitem,byref ld as double, byref lr as double, byref pd as double, byref pr as double, byref fi as integer, byref fo as integer) dim i, c as integer dim g as FolderItem dim ldd,lrr,pdd,prr as Double dim ffi,ffo as integer fo=fo+1 c=f.Count for i=1 to c g=f.TrueItem(i) if g<>nil then if g.Directory then ldd=0 lrr=0 pdd=0 prr=0 ffi=0 ffo=0 dir2 g,ldd,lrr,pdd,prr,ffi,ffo ld=ld+ldd lr=lr+lrr pd=pd+pdd pr=pr+prr fi=fi+ffi fo=fo+ffo else ld=ld+g.LogicalFileDataLengthMBS lr=lr+g.LogicalFileResLengthMBS pd=pd+g.PhysicalFileDataLengthMBS pr=pr+g.PhysicalFileResLengthMBS fi=fi+1 end if end if next Exception End Sub
Property cc As MyThread
Property Protected f As DirectorySizeMBS
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Util Plugin.





Links
MBS Xojo Plugins