import os #需要完整路徑 for i in os.listdir(path): if i.endswith((".png",".jpg","jpeg")): flist.append( path + '/' + i) print('.' , end='' ) flist.sort()
included_extenstions = ['xhtml', 'html', 'htm', 'opf' , 'ncx' ,'xml'] # walk 遞迴取檔 for root,d,f in os.walk(path): for file in f: if any(file.endswith(ext) for ext in included_extenstions): print(os.path.join(root,file))