您的位置:首页 > 编程语言 > Python开发

Python下获取当前目录中的所有子目录

2014-05-19 20:07 399 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐