#!/usr/bin/env python # coding:UTF-8 import os filepath = ‘/root/python‘ dir_files_list = sorted([os.path.join(filepath, dirfiles) for dirfiles in os.listdir(filepath)]) #print dir_files_list def fun(rootdir): for dirfiles in sorted(os.listdir(rootdir)): path_dirfiles = os.path.join(rootdir, dirfiles) if os.path.isdir(path_dirfiles): print ‘\033[34;1m%s\033[0m‘ % path_dirfiles fun(path_dirfiles) #递规调用fun() else: print ‘%s‘ % os.path.split(path_dirfiles)[1] if __name__ == "__main__": fun(filepath)
本文出自 “JUST DON'T GIVE UP!” 博客,请务必保留此出处http://zliang90.blog.51cto.com/3001993/1360052