Thursday, February 9, 2012

GetFileSize function

Function GetFileSize(folderspec As String) As Variant
'   Returns an array of file size that match FileSpec
    Dim fs, f, f1, fc, s
    Dim FileArray() As Variant
    Dim FileCount As Integer
    Dim filesize As String
 
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.Files
    FileCount = 0
 
    For Each f1 In fc
        s = f1.Size
        filesize = s
        FileCount = FileCount + 1
        ReDim Preserve FileArray(1 To FileCount)
        FileArray(FileCount) = filesize
        GetFileSize = FileArray
    Next
End Function




No comments:

Post a Comment