Find all files of a particular extension in folder AND subfolders

Does anyone have an efficient way of searching a folder and all subfolders for a particular type of file, lets say all *.txt files.
I can load all files from a given folder no problem.
The issue is when there are subfolders with varying numbers of levels.

If Igor cannot do this directly can I use something analogous to the Matlab "system" command?

I would like a way to return the full path to each found file, any suggestions?
hrodstein wrote:
See the PrintFoldersAndFiles example function in the help for IndexedDir.


Thanks for the tip. This works pretty well but is not quite as general as it could be.
I am dealing with a system that has lots of users storing data all over the place.

Imagine the following Directory structure (I have tried to show levels by size and spacing):


E:Data:


a.txt
b.txt
sub1:




c.txt
d.txt
sub2:




e.txt
sub3:



f.txt



This example will only find file f.txt, and will not find a-e.txt.
This is definitely a starting point, I'll see what I can do.

This is a quick outline of what you need to do:

1) In your function listthem use indexedfile to list all the txt files. Append the list to a string, thefiles
The function prototype is:

Function listthem(directoryStr, theFiles)
String directoryStr, &theFiles


Note that the ampersand means that you are passing by reference, not by value. The entire string gets added to after you return from the function.

2) Then list all the directories in the current directory using indexeddir. Iterate through all the directories in a for loop calling listthem recursively. thefiles string gets added to as you walk the tree.

3) You have to call the function with a zero length string to start with.