I have a Xojo program that gets all of the folder names in a specific directory on our company LAN, then lists them in a ComboBox. It is very slow, and takes about 20 seconds to come up with the list. There are about a 130 folders in directory. LAN speeds to that directory are plenty fast, and outputting the names to a text file from scripting is super fast. Is there a more effecient way for me to code this using Xojo?
Here’s the code.
Dim BASE_PATH as string ="\\SERVERNAME\source$\software\WORKSTATION\"
dim VP as FolderItem
VP = GetFolderItem(BASE_PATH)
dim VPArray () as string
Dim VP2 As FolderItem
If VP <> Nil And VP.Directory Then
Dim items As Integer = VP.Count
For i As Integer = 1 To items
VP2 = VP.Item(i)
If VP2.Directory Then
Xojo’s file recursion is notoriously slow in this regard (at least on Windows). Most folks use declares or MBS for this.
Take a look at this relatively recent thread:
Simpler than I expected
I added a parameter [Filemask()] to the function and then modified
for j as Int32 = 0 to d.Ubound
for j as Int32 = 0 to d.Ubound
For q as Integer=0 To FileMask.Ubound
If d(j).Right(3)=FileMask(q) Then Files.Append d(j)
The added parameter needs to be included in the call within the loop as well.
Overall, there’s an barely perceptible drop in execution speed which is absolutely tolerable. With 25k files it add…
Not able to makes head nor tails out of that example.
Take a look at this post. It’s nested in a link or two.
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…
No help. Riddled with errors. Doesn’t like Funtion/End Function
You remove those lines. You need to make a method that matches the Function definition line in the IDE, then paste in the code from the between Function…End Function.
I did that too, of course. That’s where is gets really riddled with errors.
I put together an
example project for you, modified from this post:
The following will give you a list of directory entries, very quickly (on Win32 target at least).
Function FastItems(extends f as FolderItem) As FolderItem()
#if Not TargetWin32
// Return all of the files within a folder in the quickest way possible.
// courtesy: http://forums.realsoftware.com/viewtopic.php?f=1&t=13692&st=0&sk=t&sd=a&hilit=folderItem+aaron&start=15
// With modificaitons by me to use NativePath, corrected a minor bug and ignore ".", ".." en…
Thanks. I was able to modify that with my LAN share. Unfortunately, it isn’t any faster than my current code.
Unfortunately that’s as much as I can help with this. Hopefully someone will join the discussion that has a fast routine for file iteration on Windows.
Wound up just using PowerShell to get the info. Went from taking 35 seconds to under 2 seconds.