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.
Hey this looks good, can you use this same thing to reference files in a folder, instead of import?
Definitely. I don’t remember the command off the top of my head, but I’m sure it’s “open” or “file.” When you open them, just remember to save the session otherwise it will overwrite the previous version.
🙂
Thank you for this little nugget…really nice to call a procedure within itself. I thought that would have crashed maya for some reason 😉