# getFiles.py (c) 2010 Walter Behrnes # Verision 1.0 # Author: Walter Behrnes # # # Description: # This script returns a list of files of a specified type # containing a series of specified text with in the name) seperated with a "\n" # # Use: # getFiles.py "FILE EXTENTION" "SEARCH PARAMETERS SEPERATED BY commas" "FOLDER PATH" # Options: # # # Dependancies: # # # Documentation: # # Examples: # getFiles.py ".ma" "_PXY,_MID,_REN" "/home/username/Procedure" # # this example would find all .ma files containing _PXY,_MID, and _REN # with in their names in the "/home/username/Procedure directory" # # Notes: # # Bugs: # # Original: # Revisions: # # To-do's: # import sys #EDIT THIS TO SUITE YOUR OPERATING SYSTEM if sys.platform == 'win32': sys.path.extend (['', 'C:/WINDOWS/system32/python25.zip', 'C:/Python25', 'C:/Python25/DLLs', 'C:/Python25/Lib', 'C:/Python25/Lib/plat-win', 'C:/Python24/lib/lib-tk', 'C:/Python24/lib/site-packages','C:/Python24/tcl/tcl8.4']) else: sys.path.extend (['/usr/lib/python2.4','/usr/lib64/python2.4']) import os import re #GET FILE TYPE FROM USER file_type = sys.argv[1] #GET FOLDER PATH folder_path = sys.argv[3] #GET SEARCH STRINGS searchstring = sys.argv[2] #SPLIT INTO ARRAY searchStrings = searchstring.split(',') #MAKE ARRAY TO RETURN returnFiles = [] #GET FILES cur_Folders = os.listdir(folder_path) #print "CURRENT DIRECTORY: \n", folder_path for objects in cur_Folders: #GATHER FOLDERS curPath = folder_path+"/"+objects #CHECK IF IS FOLDER if os.path.isdir(curPath): #COMPILE LIST OF FILES curFiles = os.listdir(curPath) #LOOP THROUGH FOLDERS for files in curFiles: #LIST FILES IN CURRENT FOLDER if os.path.isfile(curPath+"/"+files): #SPLIT EXTENTION fileTest = os.path.splitext(curPath+"/"+files) #TEST IF .ma FILE if fileTest[1] == file_type: #print "\t\t", files #LOOP THROUGH SEARCH STRINGS for searchItems in searchStrings: #TEST IF SEARCHSTRING IS IN FILE NAME if re.search(searchItems,files): #APPEND FILE TO RETURNFILE ARRAY returnFiles.append(curPath+"/"+files) #PRINT FILE NAMES TO SCREEN SO THEY GET RETURNED TO MAYA for thefiles in returnFiles: print thefiles