Hi All,
I have to browse a directory for available files. FolderItem.Count uses a lot of resources and slow things down. I was looking in Eugene Daikin’s book for a replacement API call but cannot find one.
How can I best browse a directory (on Windows) which is not resource-consuming and without any third-party solution?
Thank you very much for your help which is appreciated.
Have a nice day.
Chris
Thank you so much Tanner Lee,
I appreciate your help and advice so much. You just solved a problem which I was busy with the whole afternoon without any progress.
I tried it and it worked fast and flawlessly.
I also want to thank Neil Burkholder for his excellent solution.
Wish you both all the best and thanks again.
Chris
Just converted the GetFiles function to the new Xojo 2019 r3.0 version. Credits for this function still go to Neil Burkholder.
Here it is :
First create a new “Function” with parameter :
strPath As String
and :
String() as return type
f_SelectedDirectory is type FolderItem
Next is the code for the body of the function :
// Original function created by Neil Burkholder
// This version is adapted for Xojo 2019 r3.0
// Call : strFiles() = GetFiles(f_SelectedDirectory.NativePath)
var strFiles() As String
var strD() As String
var intLoop As Integer
var mmbResult As New MemoryBlock(40000) //A WIN32_FIND_DATA structure
if strPath.Right(1) <> "\" Then strPath = strPath + "\"
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
var FindHandle As Integer = FindFirstFile("\\\\?\" + strPath + "*" + Chr(0), mmbResult)
// Walkthrough folder and get a list of directories and files
If FindHandle > 0 Then
Do
if mmbResult.int32value(0) = 16 Then
// If this is a directory then resurse through the directory to get all files
if mmbResult.WString(44) <> ".." and mmbResult.WString(44) <> "." Then
strD = GetFiles(strPath + mmbResult.WString(44) + "\")
if strD.LastRowIndex > -1 Then
for intLoop = strD.FirstRowIndex To strD.LastRowIndex
strFiles.AddRow(strD(intLoop))
next intLoop
end if
end if
else
strFiles.AddRow(strPath + mmbResult.WString(44))
end if
Loop Until Not FindNextFile(FindHandle, mmbResult)
Call FindClose(FindHandle)
End If
Return strFiles()
I was nicely surprised how easy this function was converted to the new Xojo 2019 r3.0 framework.
Hope this will help other people as well.
Chris