title: Loop through files in all directories in vb
body: <p>WIth below code I'm trying to loop through all .prt files in all directories, but getting error:</p>
  
  <blockquote>
    <p>file is a type and cannot be used as expression.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>    Dim PartsPath as string = "D:\workdir\1"
      '''' Get file size
      Dim strFileSize As String = ""
      Dim di As New IO.DirectoryInfo(PartsPath)
      Dim aryFi As IO.FileInfo() = di.GetFiles("*.prt")
      Dim fi As IO.FileInfo
      Dim f1 as integer = f
      For Each fi In aryFi
          strFileSize = (fi.Length / 1048576).ToString()
          objExcel.cells(f1, 4).value = FormatNumber(strFileSize, 2)
          f1 = f1 + 1
      Next
  
      For Each file In di.GetFiles("*.prt", SearchOption.AllDirectories) 
  </code></pre>