title: Working in VBA Excel can I get the total size of all files in a directory excluding subdirectories
body: <p>I am currently working on a routine to compare two folders to see if the contents seem to be the same. The criteria is that if the two folders have the same number of files and the same total size, then in all probability they contain the same files... more checks will be carried out post this test. The issue is that a given folder may have one or more subfolders in it and I want these to be ignored (again this will be dealt with later).</p>
  
  <p>I can get the total folder size by the code below but this includes the size of subfolders. For speed reasons I do not wish to cycle through the individual files and sum the file sizes. Is there any way to get the total size of all of the files (excluding subfolders) in a given folder?</p>
  
  <pre><code>strDir = ActiveCell.Offset(RowOffset:=x).Value
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  
  Set objFiles = fso.GetFolder(strDir).Files
  
  Set Folders = fso.GetFolder(strDir)
  
  FileCount = objFiles.Count
  DirsSize = Folders.Size
  
  ActiveCell.Offset(columnOffset:=1, RowOffset:=x).Value = FileCount
  ActiveCell.Offset(columnOffset:=2, RowOffset:=x).Value = DirsSize
  </code></pre>
  
  <p>Notes:</p>
  
  <pre><code>This segment also gets the number of files (excluding subdirectories) in the folder.
  
  The segment may be called several hundred times by the routine and each folder may contain
  several thousand files hence the reluctance to sum file sizes via a loop.
  
  Strdir contains a valid folder path,
  
  The above code works but the size is the size of the folder including subdirectories which is
  not what I want.
  </code></pre>