p是输入目录
代码如下
import os
def getDirList(p): #
b = [];
filepath=p
if filepath=="":
return b
filepath = filepath.replace( "/","\\")
if filepath[ -1] != "\\":
filepath = filepath+"\\"
a = os.listdir(filepath)
#print(a)
for x in a:
path = filepath+x
print(path)
if os.path.isdir(path):
c = getDirList(path);
if c==[]:
b.append(path)
else:
print(c)
b=b+c
return b
本文出自 “技术的海洋” 博客,请务必保留此出处http://swiftzhy.blog.51cto.com/7278211/1413873
Python下获取当前目录中的所有子目录,布布扣,bubuko.com
原文地址:http://swiftzhy.blog.51cto.com/7278211/1413873