I had a question regarding how to list only the folders, not the files within the folders, in Python. I currently have this few lines of code which will join every file in ever folder into one list. If I have 50 folders, I want to make 50 different lists instead of one large one.
Folder_files = []
for dirName, subdirList, fileList in os.walk(Path):
for filename in fileList:
if "A_0" in dirName:
if ".xml" in filename.lower():
Folder_files.append(os.path.join(dirName,filename))
I know I have Folder_files as my only list at the moment, however I expect to experiment by using a for loop to have different lists.
I am just in need of help finding out how to read up to the folder A_0
before selecting the .xml
files.
Before appending the files to the list. I attached a sample code of what I am thinking it will look like below:
for dirName, subdirList, fileList in os.walk(Path):
for filename in fileList:
if "A_0" in dirName:
#for loop in here
#Set up all folders
if ".xml" in filename.lower():
#Add files in folder to the appropriate file list