python3 获取一个本地目录下所有文件的绝对路径

代码如下:

import os

def get_abs_paths(directory, totalPathFiles=[]):
    '''
    此函数旨在获取directory目录下,所有文件的绝对路径,
    并放在totalPathFiles里。
    directory,目标目录。   
    '''
    FFs = os.listdir(directory)
    for f in FFs:
        totalPathFile = os.path.join(directory, f)
        if os.path.isfile(totalPathFile):
            totalPathFiles.append(totalPathFile)
        else:
            get_abs_paths(totalPathFile)
    return totalPathFiles


if __name__ =="__main__":    
    directory = r"D:\Cesium2"
    totalPathFiles = get_abs_paths(directory)

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/85235365