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
Python下获取当前目录中的所有子目录,布布扣,bubuko.com
时间: 2024-10-12 06:32:12