All,
What is the best way to check to see if there is data in a directory before deleting it? I am browsing through a couple pages to find some pics using wget and of course every page does not have an image on it but the directory is still created.
dir = 'Files\\%s' % (directory)
os.mkdir(dir)
cmd = 'wget -r -l1 -nd -np -A.jpg,.png,.gif -P %s %s' %(dir, i[1])
os.system(cmd)
if not os.path.isdir(dir):
os.rmdir(dir)
I would like to test to see if a file was dropped in the directory after it was created. If nothing is there...delete it.
Thanks, Adam
Try:
or
Here is the fastest and optimized way to check if the directory is empty or not.
If the empty directories are already created, you can place this script in your outer directory and run it:
What if you did checked if the directory exists, and whether there is content in the directory... something like:
LBYL style.
for EAFP, see mouad's answer.