氣輕Python115 walk函數(shù)
?
在F:\a文件夾里有1和2文件夾以及文件a.txt。文件夾1和2中分別包含文件11.txt,12.txt和21.txt,22.txt
?
import os
?
def qipy115():
?
??? for root, dirs, files in os.walk("F:/a", topdown=False):
??????? print('\nroot:',root)
??????? print('dirs:',dirs)
??????? print('files:',files)
?
??? return
?
?
if __name__ == "__main__":
??? qipy115()
?
執(zhí)行結(jié)果
root: F:/a\1
dirs: []
files: ['11.txt', '12.txt']
?
root: F:/a\2
dirs: []
files: ['21.txt', '22.txt']
?
root: F:/a
dirs: ['1', '2']
files: ['a.txt']
標(biāo)簽: