Results 1 to 10 of 193

Thread: Appendix Thread 2. ( Codes for other Threads, HTML Tables, etc.)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Some extra notes for this forum post: https://eileenslounge.com/viewtopic....313578#p313578

    I took a look at this



    Here is the test file and folder details https://i.postimg.cc/pX90bM2Q/MM-Pro...est-Folder.jpg https://i.postimg.cc/2SN78v0H/MM-Pro...est-Folder.jpg


    Sample File ___ sample.wmv https://app.box.com/s/leu06ql1fu9uzt59wnoizedg85qoo7k4
    Folder ___ MMPropertyTest https://app.box.com/s/27u7dyjee3rez44pdjq52uu2e7tgzu8v
    File with coding in ___ Movie Maker Versions.xls https://app.box.com/s/axle7nflnmgkfbztto1wsmhc2ml2ynes
    ' c009 Built in VBA FileLen( ) way , ' c109 Scripting Runtime Object Library way
    Code:
    Sub SumSnbs_() '         http://www.eileenslounge.com/viewtopic.php?p=313578#p313578     https://www.snb-vba.eu/VBA_Bestanden.html#L_2.17
    Dim FileThing As Variant, FolderThing As Variant, FlFldrNme As String
    '  c009   Built in  VBA FileLen( )  way
     Let FlFldrNme = Dir(PathName:=ThisWorkbook.Path & Application.PathSeparator & "*", Attributes:=vbDirectory + vbNormal)
        Do While Left(FlFldrNme, 1) = "."    '    https://www.accessforums.net/showthread.php?t=60879&p=325335#post325335
         Let FlFldrNme = Dir
        Loop '  While Left(FlFldrNme, 1) = "."
        Do While FlFldrNme <> ""
        Debug.Print FlFldrNme & "     ";
         Let FileThing = FileLen(ThisWorkbook.Path & "\" & FlFldrNme) '  VBA built in way
            If FileThing = 0 Then  '  Probably got a Folder
            '  c109    Scripting Runtime Object Library  way
             Let FolderThing = CreateObject("scripting.filesystemobject").GetFolder(ThisWorkbook.Path & "\" & FlFldrNme).Size
             Debug.Print FolderThing
            Else  '  Probably got a file
             Debug.Print FileThing & "     "; '  VBA built in way
             Let FileThing = CreateObject("scripting.filesystemobject").GetFile(ThisWorkbook.Path & "\" & FlFldrNme).Size
             Debug.Print FileThing            '  c109    Scripting Runtime Object Library  way
            End If
         Let FlFldrNme = Dir
        Loop ' While vTemp <> ""
    End Sub
    Results:
    Code:
     sample.wmv     643170      643170 
    Microsoft Scripting Runtime  Library referrence.JPG     96231      96231 
    snbsize.JPG     96857      96857 
    Windows Script Host Object Model  Library referrence.JPG     85009      85009 
    MySubFolder      96857 
    Movie Maker Versions.xls     1630720      1630720
    Conclusions:
    Both the in-built VBA file size function and the file size from scripting file system object appear to give a nice Bytes size number
    The folder size from the scripting file system object gives a similar number. (Note that in the folder, MySubFolder, is a single file, snbsize.JPG, and I also ran the code with nothing in MySubFolder and got a size of 0. So it would appear that an empty folder has a size of the things in it.




    ' c309 Microsoft Shell Controls And Automation way

    Code:
    Sub MicrosoftShellControlsAndAutomation() '  referrence  Microsoft Shell Controls And Automation     https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg     https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg
    '  c309  Microsoft Shell Controls And Automation   way
    Dim oShell As Shell32.Shell: Set oShell = New Shell32.Shell
     Dim Itm As Shell32.FolderItem, objFolder As Shell32.Folder: Set objFolder = oShell.Namespace(ThisWorkbook.Path)
        For Each Itm In objFolder.Items
         Debug.Print Itm.Name & "   " & Itm.Size & "   " & objFolder.GetDetailsOf(Itm, 1)
        Next Itm
    End Sub
    Results:
    Code:
     sample.wmv   643170   628 KB
    Microsoft Scripting Runtime  Library referrence.JPG   96231   93,9 KB
    snbsize.JPG   96857   94,5 KB
    Windows Script Host Object Model  Library referrence.JPG   85009   83,0 KB
    MySubFolder   0   
    Movie Maker Versions.xls   1630720   1,55 MB
    Conclusion:
    The .size and .GetDetailsOf(Itm, 1) seem to give different numbers and the .size looks like the nice number
    It seems to be broken for a folder. The .size gives 0 and the .GetDetailsOf(Itm, 1) gives nothing




    ' c709 VBA Open For Input Close way

    Code:
    '   c709    VBA  Open For Input  Close    way
    Sub c709() '  https://www.snb-vba.eu/VBA_Bestanden.html#L_2.17    Size: file size / file length in bytes
    Dim vTemp As Variant
    Open ThisWorkbook.Path & "\" & "sample.wmv" For Input As #1
     Let vTemp = LOF(1): Debug.Print vTemp '  643170
    Close
    
    'Open ThisWorkbook.Path & "\" & "MySubFolder" For Input As #1    '  Does not work for Folders
    ' Let vTemp = LOF(1): Debug.Print vTemp
    'Close
    End Sub
    Result:
    643170
    Conclusions
    For a file, this returns the nice Byte number. (It does not work for a folder)




    The final way suggested by snb, the Windows Script Host Object Model look like it needs some more consideration, so I will look at that in the next post, https://www.excelfox.com/forum/showt...ll=1#post23918
    Last edited by DocAElstein; 01-19-2024 at 03:40 PM.

Similar Threads

  1. VBA to Reply All To Latest Email Thread
    By pkearney10 in forum Outlook Help
    Replies: 11
    Last Post: 12-22-2020, 11:15 PM
  2. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  3. Replies: 19
    Last Post: 04-20-2019, 02:38 PM
  4. Search List of my codes
    By PcMax in forum Excel Help
    Replies: 6
    Last Post: 08-03-2014, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •