I am a python newbie, I have given a task to continuously go in a directory and fetch for a empty sub directory or a files . if the directory is empty it should write the path to a folder.txt , if the directory has files in it should write a path of that file. For example:
Dir a contains:
a/apple/mango/ess.txt
a/gat.xml
a/apple/asl/cdr/opa/est.py
a/apple/dse/
a/dews
Output (folder.txt) file should be :
a/apple/dse/
a/dews
Output (file.txt) file should be :
a/apple/mango/ess.txt
a/gat.xm
a/apple/asl/cdr/opa/est.py
I tried using this logic:
for subdir, dirs, files in os.walk(path):
for files in dirs:
fp1 = (os.path.join(path, files))
print (fp1)
if len(os.listdir(fp1)) == 0:
print("Directory is empty")
folder_added.write("\n Empty folder found %s \n" % (fp1))
but it goes only till two sub folders.