I seem to have partly ( or possibly fully ** ) answered my question while I was preparing it. But my answer is perhaps a bit messy, or wrong, or right. I don’t know. So I am looking for help / guidance, any comments / suggestions, etc.
What I am basically doing is comparing some files, (programmatically to do it efficiently as I may have a lot of files) .
The files should be the same or similar, but may have small differences in properties.
In particular the exact size, is useful for me to get at programmatically.
Manually I see a few different sizes given, for example for the uploaded video file example, sample.wmv , I can get these numbers from three different ways:
_Hovering over in the explorer window gives me 628 KB
_The explorer shown size property gives me 629 KB
_The right click on file in the explorer windows, left click properties way gives me a few numbers:
Size: 628 KB (643.170 Bytes)
Size
On Disk : 632 KB (647.168 Bytes)
( that Size On Disk number seems to vary a bit from computer to computer, - I guess that makes sense? )
https://i.postimg.cc/WbTKVfVC/Get-File- ... nually.jpg ,
https://bit.ly/3vw1DxN _.________________
This is my coding attempts so far
Code: Select all
Sub GetFileSizeVBA() ' https://eileenslounge.com/viewtopic.php?f=30&t=40533 https://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-2-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=23916&viewfull=1#post23916 https://www.excelfox.com/forum/showthread.php/2936-YouTube-Video-making-and-editing-etc-coupled-to-excelfox-(-windows-Movie-Maker-)/page2#post23774
Rem 1 windows shell object way https://www.youtube.com/watch?v=jTmVtPHtiTg
' Early Binding windows shell object '
'Dim objShell As Shell32.Shell: Set objShell = New Shell32.Shell ' 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
' A bit Later Binding windows shell object '
Dim objShell As Object: Set objShell = CreateObject("Shell.Application")
Dim objFolder As Shell32.Folder: Set objFolder = objShell.Namespace(ThisWorkbook.Path) ' Put sample.wmv in same folder as the file from which this macro is running
Dim Fil As Shell32.FolderItem
For Each Fil In objFolder.Items
If Fil.Name = "sample.wmv" Then
Debug.Print objFolder.GetDetailsOf(Fil, 1) ' From this code line 628 KB Hover Over gives 628 KB Right click properties gives Size: 628 KB (643.170 Bytes) Size on Disk 632 KB (647.168 Bytes) Size in explorer window 629 KB https://i.postimg.cc/WbTKVfVC/Get-File-size-manually.jpg https://i.postimg.cc/Z5DDrbNz/Hover-Over-gotten-File-Size.jpg https://i.postimg.cc/XvRHzsx2/Right-click-properties-gotten-File-Size.jpg https://i.postimg.cc/sg2NQQvJ/Size-shown-in-explorer.jpg https://i.postimg.cc/PqpVygbp/Hover-Over-gotten-File-Size.jpg https://i.postimg.cc/vHhKZLHB/Size-shown-in-explorer.jpg
Else
End If
Next Fil
Rem 2 Scripting Runtime Object Library way ' https://www.youtube.com/watch?v=zHJPliWS9FQ
' Early Binding
'Dim FSO As Scripting.FileSystemObject: Set FSO = New Scripting.FileSystemObject ' https://i.postimg.cc/d1GHPGxJ/Microsoft-Scripting-Runtime-Library.jpg
' Late Binding
Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Fl As Object: Set Fl = FSO.GetFile(ThisWorkbook.Path & "\" & "sample.wmv") ' Put sample.wmv in same folder as the file from which this macro is running
Debug.Print Fl.Size ' gives 643170
End Sub
628 KB
643170
So my question is, does anyone know of any other ways to get all those numbers,
Perhaps there is a Power Shell way to do it ? , but is so I would want to know how to do that from within VBA
**Or, thinking a bit laterally, is the answer for what I am finally wanting to do, compare files from their size, something like, …. Use the FSO way (Rem 2) in my coding ) , since for comparing file sizes, that 643170 number would be the best/ most accurate and consistent / most appropriate for file comparing purposes. ?
Thanks,
Alan
_._________________________________
sample.wmv https://app.box.com/s/leu06ql1fu9uzt59wnoizedg85qoo7k4