What is the most pythonic way to test whether a folder, its subfolders, all their subfolders, etc. are empty? I am aware of os.listdir() and have come up with the function below, but it seems that there would be a standard function for this already (though several searches turned up nothing).
def is_empty(target_folder): #Recursively tests whether a folder is empty.
import os
if [i for i in os.listdir(target_folder) if not
os.path.isdir(os.path.join(target_folder,i))]:
return False
else:
return all([is_empty(os.path.join(target_folder,i)) for i in
os.listdir(target_folder) if
os.path.isdir(os.path.join(target_folder,i))])