Read contents of directory

  1. 7 months ago

    Neil B

    16 Mar 2017 Pre-Release Testers

    Is there a fast way to parse the contents of a directory using Xojo? In VB Net I can get all files from a folder and half a dozen sub folders (over a 1,000 files) almost instantly. Doing the same thing with Xojo using the practices recommended here it takes so long Xojo becomes unresponsive.

    Any suggestions? Or is this a quirk of Xojo?

    -image-

    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
  2. Christian S

    16 Mar 2017 Pre-Release Testers, Xojo Pro Germany

    If you want more speed than FolderItem class in old/new framework, you can try MBS Plugins with FileListMBS class:

    http://www.monkeybreadsoftware.net/class-filelistmbs.shtml

    We achieve high speed by not using folderitems.

  3. Thomas E

    16 Mar 2017 Pre-Release Testers

    @ChristianSchmitz … you can try MBS Plugins with FileListMBS class…

    I see it as SPAM because there is no disclaimer who is writing such a "BUY IT" reply.

    Who needs to a plugin anyway?
    See Fastest File Finding... where Andrew Lambert posted a link to the old forum .

    There is a quick solution using WinAPI calls.

  4. Emile S

    16 Mar 2017 Europe (France, Strasbourg)

    @Thomas E I see it as SPAM

    It is not.

  5. Neil B

    16 Mar 2017 Pre-Release Testers

    Ok the declares are what I was looking for, as this is windows specific. Thanks Thomas.

    I'm a little green with declares. How can I modify the ListDir from the link to do the folling:

    1. Recurse through all subfolders and include all files from sub folders.
    2. Return the full (native) path, instead of only the file name.

    Thanks again.

  6. Emile S

    16 Mar 2017 Europe (France, Strasbourg)

    >2. Return the full (native) path, instead of only the file name.
    http://docs.xojo.com/index.php/FolderItem

    Use .NativePath instead of .DisplayName (or Name)

  7. Neil B

    16 Mar 2017 Pre-Release Testers

    @Emile S Use .NativePath instead of .DisplayName (or Name)

    I know how to use folderitems. I'm talking about declares.

    Can anyone show me how to get the GetFullPathName declare to work?
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa364963(v=vs.85).aspx

  8. Thomas T

    16 Mar 2017 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)
    DWORD WINAPI GetFullPathName(
      _In_  LPCTSTR lpFileName,
      _In_  DWORD   nBufferLength,
      _Out_ LPTSTR  lpBuffer,
      _Out_ LPTSTR  *lpFilePart
    );

    Translates roughly to

    declare GetFullPathName lib "??" alias "GetFullPathNameW" (name as CString, bufLen as Integer, bufPtr as Ptr, filePartPtr as Ptr) as Integer

    Don't know the lib name, but it's the same as for the others, probably.

    You'd then call it like this:

    dim buf as new MemoryBlock (1024)
    dim nameLen as Integer = GetFullPathName (f.NativePath.ConvertEncoding(Encodings.UTF8), buf.Size, buf, nil)
    dim fullPath as String = buf.CString(0).DefineEncoding(Encodings.UTF8)
  9. Emile S

    16 Mar 2017 Europe (France, Strasbourg)

    @Neil B I know how to use folderitems

    Sirry, NAP collateral effect.

  10. Tim H

    16 Mar 2017 Pre-Release Testers Portland, OR USA

    Since you know the path you started with, you can build the path as you recurse the folders. It's what I do.

  11. Neil B

    17 Mar 2017 Pre-Release Testers

    @Tim H Since you know the path you started with, you can build the path as you recurse the folders. It's what I do.

    It looks like it will take some more fooling around. Thanks for your help.

  12. Julian S

    17 Mar 2017 Pre-Release Testers, Xojo Pro UK
    Edited 7 months ago by Julian S

    @Thomas E I see it as SPAM because there is no disclaimer who is writing such a "BUY IT" reply.

    Who needs to a plugin anyway?

    Lots of people have it and don't know what it can do, so its worth pointing out.

    I guess it boils down to how much you value your time.

    2.5 hours (if you know what you're doing) of R&D, coding and testing VS buying a plugin for £50.

    If your time is worth £25/h or less, then code it yourself :)

    If you're writing it for a client, pass on the cost then you can reuse the plugin over and over as well as it having other functionality you might use.

    Then factor in writing it for the mac if you need cross platform in the future and you can see that plugins really are value for money.

  13. Edited 7 months ago by Norman P

    I think, in part, what Thomas is pointing out is, that besides "hey use the plugin", there's no attempt to answer the question at hand in any other way like pointing out that there are other alternatives (iterating folderitems, declares, etc)

    It might as well just be an advertisement on the forum pages saying "Buy the MBS plugins."

    Correct me if I missed the mark @Thomas E

  14. Julian S

    17 Mar 2017 Pre-Release Testers, Xojo Pro UK

    Yeah I can see that point of view too, but as Christians plugins do encompass an awful lot, its easy to miss something even if you have it (as I do) :) I don't think a lack of attempting to answer the problem is a mute point, after all, neither have we ;) The more bumps, the more someone might chime in with an answer :)

    PS. More :) :) :) I didn't use enough (I need sleep)

  15. Note I didn't say they do not encompass a lot of functionality
    Just that we do get complaints about non-answers that just plug MBS without really addressing the question beyond saying "hey if you used my plugins ..."

    This has been true since way before these forums existed & I'm sure one could scour the old NUG mailing lists & old forums for exactly the same kinds of complaints

    Like you I'm just saying that I can see Thomas point of view

  16. Julian S

    17 Mar 2017 Pre-Release Testers, Xojo Pro UK
    Edited 7 months ago by Julian S

    @Norman P Just that we do get complaints about non-answers that just plug MBS without really addressing the question beyond saying "hey if you used my plugins ..."

    IMHO, Peeps need to lighten up :) Xojo would be worse off without MBS, soooo much missing functionality ;)

    If I wrote a plugin, my next app would be one to monitor the forums and autopost replys when someone mentioned keywords about something it could ;)

    Ooo, maybe Christian has one (where's that shifty eyes emoji)

    PS. Sorry for polluting this thread

  17. Thomas T

    19 Mar 2017 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)
    Edited 7 months ago by Thomas T

    I agree somewhere with Norman on this - at least in general terms. A reply that suggests to use the MBS plugins should at least indicate an example or reference to one, or some pointers which functions to use. The MBS plugin functionality is huge and even I have sometimes trouble finding something I know that must be in there. I usually then email Christian or chat to him via his Website, but I have the advantage of being in the same time zone, so he's usually quick at responding. People in the U.S. may not get a quick response, hence a bit more detail here would be fair to expect.

    In this case, though, Christian has pointed out the documentation of the relevent class, so the reader only needs to read over the few dozen functions to find the ones that would help. In this particular case, even just using the FileListMBS class will speed up things automagically.

  18. Thomas E

    20 Mar 2017 Pre-Release Testers

    @Norman P I think, in part, what Thomas is pointing out is, that besides "hey use the plugin", there's no attempt to answer the question at hand in any other way like pointing out that there are other alternatives (iterating folderitems, declares, etc)

    It might as well just be an advertisement on the forum pages saying "Buy the MBS plugins."

    Correct me if I missed the mark @Thomas E

    Excatly. And in case there is such an advertisement there should be at least a disclaimer.

  19. Thomas T

    20 Mar 2017 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)
    Edited 7 months ago by Thomas T

    @Thomas E Excatly. And in case there is such an advertisement there should be at least a disclaimer.

    Well, how much does Christian really need to advertise that his plugins are not free?

    I'd assume that everyone knows about MBS plugins already, and that they're not free. And if they don't, well, then it's good Christian points that out for those who need a solution.

    This is a fairly small community, and unless someone can accuse Christian of false advertising or some other kind of fraudulent behavior, I don't think this needs to be made into a problem.

  20. Beatrix W

    20 Mar 2017 Pre-Release Testers Europe (Germany)

    @Thomas: the feature to ignore post from specific persons is already there. You have to open the profile of the user. Then it's contols/Ignore member.

  21. Newer ›

or Sign Up to reply!