#!/usr/bin/env python # 2.py # use UTF-8 # Python 3.3.0 # os.walk()的使用 import os # 枚举dirPath目录下的所有文件 def main(): #begin fileDir = "F:" + os.sep + "aaa" # 查找F:\aaa 目录下 for root, dirs, files in os.walk(fileDir): #begin print(root) print(dirs) print(files) #end os.system("pause") #end if __name__ == '__main__': #begin main() #end # 输出 # F:\aaa # ['4'] # ['1.txt', '2.txt', '3.txt'] # F:\aaa\4 # [] # ['5.txt', '6.txt', '7.txt']