How to getfolderitem .child with wildcard for name or extension

Hello all!

Can anyone give suggestions/best practices for using getfolderitem when wildcards for name and/or extension are necessary? For example, I want to load a listbox of all file names that are in a folder that have the extension “.prt”

Thanks in advance!
Tim

Iterate through items of the parent folderitem.child() collection , and compare the filename with your wildcard is the normal way.

Some people call out to the OS to do something like ls or dir on the command line, piped into a text file, then read the text file.
That can be faster than using .child if the folder has a lot of files in it.

Hi Jeff.

That’s the whole problem in my mind - what is the code to iterate through? Or are you saying to use the code “.child()”

To equate it to something I am familiar with- DOS code once in a folder; dir .gbl would list all files in that folder with the extension ".gbl"

Tim

This should help, I grabbed some code from my apps.
.Child() is wrong - it was .item()

New framework:

Dim d As FolderItem = specialfolder.Documents dim f as FolderItem for each f in d.Children if f.displayname.right(4)= ".GBL" then //do something end if next

old framework:

dim dir as folderitem = specialfolder.documents

mylistbox.deleteAllRows

dim x as integer
dim s as string

if dir.Count > 0 then
  for x = 1 to dir.count
    if dir.item(x) <> nil then
      s= dir.item(x).Name
      if dir.item(x).Visible then
        if dir.item(x).directory then
          //ignore or maybe add a folder to the list
        else

          if right(dir.item(x).name ,4) = ".GBL" then
            mylistbox.addrow dir.item(x).displayname
          end if

        end if
      end if
    end if
  next
end if

And if you fear to fall into an Alias, use FolderItem.TrueItem(i) instead.

Thank you!
Tim

[quote=408875:@Jeff Tullin]Some people call out to the OS to do something like ls or dir on the command line, piped into a text file, then read the text file.
[/quote]
Or, don’t write it to a file and just get the output back from the Shell:

Dim theMatches(-1) As String
Dim theShell As New Shell

theShell.Mode = 2
theShell.Timeout = -1
theShell.Execute "ls -1 """ + path + pattern + """"
Do
    theShell.Poll
Loop Until Not theShell.IsRunning
If theShell.ErrorCode <> 0 Then
    // nothing matched
Else
    theMatches = SplitB(ReplaceLineEndings(theShell.ReadAll, EndOfLine), EndOfLine)
End If
// you now have an array of files that match your pattern.

Thanks Tim,
Tim