Maya has some simple file and folder query functions. By setting up a simple recursive procedure, scripters can cycle through a directory and its respective subdirectories. Then by utilizing the file extension filtering, you can extract the desired files to open and modify.
In this example, the required inputs are a string containing the full path of the start directory. Note, Maya is funny with slashes. It uses the opposite slash than Window Explorer. Also, the second input of the subroutine is a Boolean to control recursion. A zero value just finds files in the root directory; a value of one finds all files and sub-folders.
Here’s a link to my wiki, containing this script: http://www.nickpisca.com/BLAST/index.php?title=CycleThruDir
My suggestion is to use this code as an embedded custom script. Save this file with a MEL extension and place it in your …/maya/scripts/ directory. Then whenever you access CycleThruDir in your codes, it will simplify the process.
For more information on strings and string-based functions, there is an entire chapter on this usage in YSYT – Maya MEL Basics for Designers.