#coding utf-8 import os def main(): fileDir = 'F:'+os.sep+'aaa' for root,dirs,files in os.walk(fileDir): print (root) print (dirs) print (files) os.system('pause') if __name__=='__main__': main()
>>> ================================ RESTART ================================ >>> F:aaa ['4'] ['1.txt', '2.txt', '3.txt'] F:aaa4 ['8'] ['5.txt', '6.txt', '7.txt'] F:aaa48 [] ['10.txt', '11.txt', '9.txt'] >>>