#WalkDir函数枚举目录中所有目录和文件,参数(枚举目录输出列表,枚举文件输出列表,要枚举的目录) def WalkDir(dirlist,filelist,dirname): try: ls=os.listdir(dirname) except: print "Access Deny." else: for fn in ls: temp=os.path.join(dirname,fn) if (os.path.isdir(temp)): dirlist.append(temp) WalkDir(dirlist,filelist,temp) else: filelist.append(temp) return dirlist,filelist