日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

python讀取文件夾下所有文件

作者:蒼穹之躍 更新時(shí)間: 2022-04-17 編程語言
import os

def readDir(dirPath):
    if dirPath[-1] == '/':
        print u'文件夾路徑末尾不能加/'
        return
    allFiles = []
    if os.path.isdir(dirPath):
        fileList = os.listdir(dirPath)
        for f in fileList:
            f = dirPath+'/'+f
            if os.path.isdir(f):
                subFiles = readDir(f)
                allFiles = subFiles + allFiles #合并當(dāng)前目錄與子目錄的所有文件路徑
            else:
                allFiles.append(f)
        return allFiles
    else:
        return 'Error,not a dir'

原文鏈接:https://blog.csdn.net/wenxingchen/article/details/123619732

欄目分類
最近更新