python递归函数获取某路径下所有文件

版权声明:QQ群:796245415 个人技术交流,禁止用作商业活动 https://blog.csdn.net/chen498858336/article/details/83795817
# coding = utf-8
import os
print os.listdir(os.getcwd())  # get dir all files
print os.path.dirname(__file__)  # get dir_name of file
print os.path.abspath(__file__)  # get pwd
print os.path.dirname(os.path.abspath(__file__))   # get dir of pwd
print os.path.realpath(__file__)  # get pwd
print os.getcwd()  # get current dir path


def get_filename(path):
    lists = []
    files = os.listdir(path)
    for i in files:
        file_path = os.path.join(path, i)
        if os.path.isdir(file_path):
            get_filename(file_path)
        lists.append(file_path)

    return lists


def count_file(path):
    count = 0
    list_file = get_filename(path)
    for j in list_file:
            count += 1
    return count

print count_file(r'C:\Users\Administrator\PycharmProjects\py3project\interface')
print get_filename(r'C:\Users\Administrator\PycharmProjects\py3project\interface')



猜你喜欢

转载自blog.csdn.net/chen498858336/article/details/83795817