In a directory, I am searching for files that meet a certain condition. I am using code provided by an other stackoverflow post, but it's sending me into an infinite loop for a reason I can't see.
I iterate through directories in a subdirectory. Then, I iterate through the subsubdirectories in the subdirectory, looking for ones that meet a condition. Here is my code:
import os
rootdir ="/mnt/data/SHAVE_cases"
cases = []
for subdirs, dirs, files in os.walk(rootdir):
for subdir in subdirs:
print("1")
# now we are in the file subdirectory.
# we need to see if these subsubdirectories start with "multi"
for subdirs2, d, f in os.walk(rootdir + subdir):
for s in subdirs2:
if s.startswith("multi"):
cases.append(s)
Here is another code following the advice of msi
for pathname, subdirs, files in os.walk(rootdir):
for subdir in subdirs:
for path, sub, f in os.walk(rootdir + subdir):
print(sub)
It still returns an infinite loop.