Python中的目录树列表如何获得Python中给定目录中所有文件(和目录)的列表?
3 回答
绝地无双
TA贡献1946条经验 获得超4个赞
import osfor dirname, dirnames, filenames in os.walk('.'): # print path to all subdirectories first. for subdirname in dirnames: print(os.path.join(dirname, subdirname)) # print path to all filenames. for filename in filenames: print(os.path.join(dirname, filename)) # Advanced usage: # editing the 'dirnames' list will stop os.walk() from recursing into there. if '.git' in dirnames: # don't go into any .git directories. dirnames.remove('.git')
互换的青春
TA贡献1797条经验 获得超6个赞
import osdef listdir_fullpath(d): return [os.path.join(d, f) for f in os.listdir(d)]
添加回答
举报
0/150
提交
取消