Fastest Way To Get FolderItem Names Into Array?

  1. ‹ Older
  2. 6 years ago

    Karen A

    15 Jul 2014 Pre-Release Testers

    @Tim J FileListMBS++

    Same here.

    Out of curiosity how is the speed (which might be able to be sped up more with pragmas) of the Xojo declare code compared compared to the MBS method?

  3. Tim J

    15 Jul 2014 Pre-Release Testers, Xojo Pro N. Phoenix, AZ

    The MBS method is cross platform while the Xojo declare above is Windows only.

    Having said, that, they are on par speed-wise on Windows.

  4. Dale A

    15 Jul 2014 San Diego, California, USA

    Got it! I had to retype parts of the call to the function since somehow a non-visible character crept into the name to intentionally sabotage my work.

    Thanks for the help.

  5. Karen A

    15 Jul 2014 Pre-Release Testers

    @Tim J The MBS method is cross platform while the Xojo declare above is Windows only.

    Having said, that, they are on par speed-wise on Windows.

    Is speed an issue on OS X using the code in te above method? When I've had to deal with a lot of files it has always been on Windows, not OS X.

    - Karen

  6. Karen A

    17 Jul 2014 Pre-Release Testers

    @Karen A ChildHandle = FindFirstFileW(f.AbsolutePath + "*.*", ChildData)

    One thing I forgot to mention. Note the wildcard file name specifications...

    You can substitute (or write a function where you can pass in) any valid file name wildcard string ,and have it only return files with matching names... I typically use that when looking for files with a specific extension.

    Of course on other OSes besides windows , you would have to check the filename yourself in Xojo code, but you would anyway unless they have equivalent declares.

  7. Tim J

    17 Jul 2014 Pre-Release Testers, Xojo Pro N. Phoenix, AZ

    @Karen A Is speed an issue on OS X using the code in te above method? When I've had to deal with a lot of files it has always been on Windows, not OS X.

    The MBS function is much faster on OS X than the method above. I often have to deal with millions of files in film processing (an average film = 120 minutes of DPX frames at 29.97 frames per second = 12,947,040 files...)

  8. 5 years ago

    Peter J

    is not verified 25 Apr 2015 KwaZulu-Natal, South Africa

    @Karen A Function ItemNames

    Thank you very much for this. The routines I had from Aaron Ballman turn up their toes under Xojo ( RB is fine ), so this has saved the day.

  9. 4 years ago

    Gert V

    1 May 2016 Leuven, Belgium

    Sorry to open an older thread again. Could anyone show me how I can use this function to list all files and folders in a directory, recursively?

    thanks

    Gert

  10. Michel B

    1 May 2016 Pre-Release Testers, Xojo Pro

    http://docs.xojo.com/index.php/FolderItem.Item

  11. Gert V

    1 May 2016 Leuven, Belgium

    Thanks Michel. I saw this but I can't figure out how to map the regular folderitem to the ItemNames function.

  12. Michel B

    1 May 2016 Pre-Release Testers, Xojo Pro

    @Gert VAssche Thanks Michel. I saw this but I can't figure out how to map the regular folderitem to the ItemNames function.

    The very simple example on that page precisely picks itemName from item to put it into a ListBox. Can you explain more clearly what you are trying to achieve ?

  13. Gert V

    1 May 2016 Leuven, Belgium

    When I have this:

    Dim dlg as New SelectFolderDialog
      Dim f as FolderItem
      Dim itemIdx as Integer 
      Dim dirCount as Integer
      Dim item as FolderItem
      dlg.InitialDirectory=SpecialFolder.Documents
      f=dlg.ShowModal()
      If f <> Nil then
        dirCount = f.Count
        For itemIdx = 1 to dirCount
          item = f.Item(itemIdx)
          If item <> nil Then
            DataList.addrow item.name
          End If
        Next
      end if

    I don't know how to call the ItemNames function.
    I also don't see how to use the boolean ReturnFileNames.

  14. Marco H

    1 May 2016 Pre-Release Testers Cali, Colombia

    If you want it recursively, it's easier to pass it on to a Method so it can call itself when it finds a sub folder.

    Button:

      Dim dlg As New SelectFolderDialog
      Dim f As FolderItem = dlg.ShowModal()
      
      If f <> Nil Then
        ListFiles(f)
      End If

    Method:

    Sub ListFiles(theFolder As FolderItem)
      
      Dim f As FolderItem
      If theFolder <> Nil And theFolder.Directory Then
        Dim items As Integer = theFolder.Count
        For i As Integer = 1 To items
          f = theFolder.Item(i)
          If f.Directory Then
            ListFiles(f)
          Else
            Listbox1.AddRow(f.Name)
          End
        Next
      End If
      
    End Sub
  15. Gert V

    1 May 2016 Leuven, Belgium

    Hi Marco, my first and main problem is that I don't see how to use Karen's ItemNames function.

  16. Beatrix W

    1 May 2016 Pre-Release Testers, Third Party Store Europe (Germany)

    Check out the extends keyword in the docs. This adds the itemsNames function TO the folderitem. You call it just like a method of the folderitem.

    dim myResult(-1) as string = myFolderitem.itemNames

  17. Marco H

    1 May 2016 Pre-Release Testers Cali, Colombia

    Ah :)
    See the first line:

    Function ItemNames(extends f as folderItem, ReturnFileNames as boolean = true, ReturnFolderNames as boolean = true) As String()

    Note where it says "extends f as folderItem".
    In your project, add a module. Then inside this module add the Function.
    Then you can do something like:

    Dim someFolderitem As FolderItem
    Dim someArray() As String
    someArray = f.ItemNames(true, true)
  18. Gert V

    1 May 2016 Leuven, Belgium

    Marco, that was what I was looking for indeed.
    I don't have the impression it is so much faster, so I think I'm still doing something wrong.
    So I'll investigate this a bit more this afternoon.
    This is anyhow already a step forward.

    thanks

  19. Marco H

    1 May 2016 Pre-Release Testers Cali, Colombia

    The digging of the files itself should be pretty fast.
    Adding the items to your ListBox is often the part that is slowing things down.

  20. Gert V

    1 May 2016 Leuven, Belgium

    that might be the problem indeed...
    or the fact I'm also writing all do a db (within a transaction of course)

or Sign Up to reply!