вот так можно получить список всех подпапок, начиная с указанной папки:
import os
def getListOfFolders(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFolders = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFolders.append(fullPath)
allFolders = allFolders + getListOfFolders(fullPath)
return allFolders
def main():
directory = 'd:/temp/photo/'
# Get the list of all files in directory tree at given path
listOfFolders = getListOfFolders(directory)
# Print the files
for elem in listOfFolders:
print(elem)
if __name__ == '__main__':
main()