Python实现扫描指定目录下的子目录及文件的方法
作者:互联网
def scan_files(directory, prefix=None, postfix=None): files_list = [] for root, sub_dirs, files in os.walk(directory): for special_file in files: if postfix: if special_file.endswith(postfix): files_list.append(os.path.join(root, special_file)) elif prefix: if special_file.startswith(prefix): files_list.append(os.path.join(root, special_file)) else: files_list.append(os.path.join(root, special_file)) return files_list
标签:files,os,Python,子目录,扫描,list,file,root,special 来源: https://blog.csdn.net/xcliang9418/article/details/120328157