Read contents of directory

Thanks to everyone. This is about 4 times faster than the VB Net method GetFiles(path)

Here is the working code:


dim files() as string = GetFiles("C:\\Users\\Server Computer\\OneDrive\\Job Proposals")
  

Function GetFiles(Path As String) As String()
  dim files(), Dir() as String
  if path.Right(1) <> "\" Then Path = path + "\"
  Declare Function FindFirstFile Lib "Kernel32" Alias "FindFirstFileW" (FileName As WString, FindData As Ptr) As Integer
  Declare Function FindNextFile Lib "Kernel32" Alias "FindNextFileW" (FindHandle As Integer, FindData As Ptr) As Boolean
  Declare Function FindClose Lib "Kernel32" (FindHandle As Integer) As Boolean
  
  Dim Result As New MemoryBlock(40000)  //A WIN32_FIND_DATA structure
  Dim FindHandle As Integer = FindFirstFile("\\\\?\" + path + "*" + Chr(0), Result)
  
  'walk through folder and get list of directories and files
  If FindHandle > 0 Then
    Do
      if result.int32value(0) = 16 Then
        'if this is a directory then resurse through the directory to get all files
        if Result.WString(44) <> ".." and Result.WString(44) <> "." Then
          dim d() as String
          d = GetFiles(path  + Result.WString(44) + "\")
          if d.Ubound > -1 Then
            for j as integer = 0 to d.Ubound
              Files.Append d(j)
            next
          end if
        end if
      else
        files.Append(path + Result.WString(44))
      end if
    Loop Until Not FindNextFile(FindHandle, Result)
    Call FindClose(FindHandle)
  End If
  
  Return files()
End Function