import os
def getAllDirRE(path, sp = ""):
#得到當前目錄下所有的文件
filesList = os.listdir(path)
#處理每一個文件
sp += " "
for fileName in filesList:
#判斷是否是路徑(用絕對路徑)
fileAbsPath = os.path.join(path, fileName)
if os.path.isdir(fileAbsPath):
print(sp + "目錄:", fileName)
#遞歸調用
getAllDir(fileAbsPath, sp)
else:
print(sp + "普通文件:", fileName)
getAllDirRE("D:\python")