python:遍历文件夹下的文件

import os

def test_findfile(directory, fileType, file_prefix):

fileList = []
for root, subDirs, files in os.walk(directory):
  for fileName in files:
    if fileName.endswith(fileType) and fileName.startswith(file_prefix):
      fileList.append(os.path.join(root, fileName))
return fileList

 

def list_filess():
  dir="C:\\Git\\moxyrulesnewui_python1\\org\\adv\\rules\\UIAutomation\\testcase\\"
  fileType=".py" # python 文件
  file_pre="test_" # 文件以tes_开头
  fileList = test_findfile(dir, fileType,file_pre)
  # print(fileList)
  for item in fileList:
    print(item)

你可能感兴趣的:(python,python)