文件访问遍历脚本

  1. import os
  2. path = r'E:/Data/Codes/Work/vi sdk/as3/src/classes'
  3. fileExts = ('.as')
  4. dirExceptions = ('.svn')
  5. def listAllFiles(path):
  6.     global fileExts
  7.     global dirExceptions
  8.     dirInfo = os.listdir(path)
  9.     print path
  10.     
  11.     for f in dirInfo:
  12.         if os.path.isfile(os.path.join(path, f)):
  13.             for ext in fileExts:
  14.                 if f.rfind(ext) == (len(f) - len(ext)):
  15.                     print '/t', f
  16.                     break            
  17.         else:
  18.             if dirExceptions.count(f) == 0:
  19.                 listAllFiles(os.path.join(path, f))
  20. if __name__ == '__main__':
  21.     listAllFiles(path)

你可能感兴趣的:(Python)