使用递归的方法得到一个目录下面的所有文件
作者:
Odven | 来源:发表于
2020-06-28 09:30 被阅读0次#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
import os
def recursive_get_file1(base_path):
'''
:param base_path: 目录
:return: None
'''
for base, dirs, files in os.walk(base_path):
for file in files:
file = os.path.join(base, file)
print(file)
def recursive_get_file2(base_path):
'''
:param base_path: 目录
:return: None
'''
if not os.path.exists(base_path):
return
files = os.listdir(base_path)
for file in files:
abs_file = os.path.join(base_path, file)
if os.path.isfile(abs_file):
print(abs_file)
else:
recursive_get_file2(abs_file)
if __name__ == '__main__':
# recursive_get_file1("/mnt")
recursive_get_file2("/mnt")
本文标题:使用递归的方法得到一个目录下面的所有文件
本文链接:https://www.haomeiwen.com/subject/sfrifktx.html
网友评论