New to python. I'm trying to write a code that will iterate through subfolders in a given root folder. At this point I see it as two loops. The outer loop will iterate through folders, the inner loop - through files. Subfolders may have specific files. If the specific files are found or the folder is empty the inner loop will break and the outer loop will jump to next folder. I kind of stuck with identifying correct methods to loop through folders. If os.walk() is the case than I'm not sure how to use it in this situation:
def folder_surfer():
rootdir = r'C:\Some_folder'
for directory in directories: # Outer loop. Need help with identifying correct method
for file in os.listdir(directory): # Inner loop
if file.endswith('.jdf') or len(os.listdir(directory)) == 0:
break
else:
create_jdf_file('order',directory)
Thanks in advance!