Reputation: 793
I've a bunch of test files(around 2k) which i got after running a code and some of them are empty. So i want to print the number and name of those empty text files. And all of those files have same extensions. I was trying this but didn't get the desired result.I don't know where i'm making the mistake.
for filename in os.listdir("/home/Desktop/2d_spectra"):
if filename.endswith(".ares"):
os.stat(filename).st_size == 0
print filename
else:
None
How can i do that?
Upvotes: 1
Views: 22
Reputation: 27792
You probably meant to add os.stat(filename).st_size == 0
to the if
:
for filename in os.listdir("/home/Desktop/2d_spectra"):
if filename.endswith(".ares") and os.stat(filename).st_size == 0:
print filename
else:
None
Upvotes: 1