1. 相对路径
import os source_path=r'你的目录' for root,dirs,files in os.walk(source_path): print('当前目录为:',root) print('当前目录下的子目录为:') for dirname in dirs: print(dirname) print('当前目录下的文件为:') for filename in files: print(filename)
2. 绝对路径
import os source_path=r'你的目录' for root,dirs,files in os.walk(source_path): print('当前目录为:',root) print('当前目录下的子目录为:') for dirname in dirs: print(os.path.join(root,dirname)) print('当前目录下的文件为:') for filename in files: print(os.path.join(root,filename))
标签:dirs,当前目录,python,os,子目录,print,path,root,目录 From: https://www.cnblogs.com/DidierFeng/p/18384975