[Gambas-user] Size of a directory
Tony Morehen
tmorehen at ajm-software.com
Fri Sep 21 17:30:14 CEST 2018
Here's an all Gambas function. It's recursive and includes the size of
the original directory. It's comparable in speed to du.
Public Function ScanDir(sDir As String) As Long
Dim sFile As String
Dim sPath As String
Dim hStat As Stat
Dim aDir As String[]
Dim iSize As Long
Try hStat = Stat(sDir)
If Error Then Return -1
iSize = hStat.Size
If hStat.Type <> gb.Directory Then Return iSize
Try aDir = Dir(sDir)
For Each sFile In aDir
sPath = sDir &/ sFile
Try hStat = Stat(sPath)
If Error Then Continue
With hStat
If .Type = gb.Directory Then
Try iSize += ScanDir(sPath)
Endif
Try iSize += .Size
End With
Next
Return iSize
End
On 2018-09-21 3:54 a.m., Hans Lehmann wrote:
> Hello,
>
> how do I determine the size (ilDirSize As Long) of a directory using
> Gambas?
>
> With kind regards
>
> Hans
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
More information about the User
mailing list