While using os.path.getsize() and os.path.isfile, my script returns the .DS_Store file too which I do not need. How do I ignore those?
import os
root = "/Users/Siddhartha/Desktop/py scripts"
for item in os.listdir(root):
if os.path.isfile(os.path.join(root, item)):
print item
Assuming you want to ignore all files that start with .
:
import os
root = "/Users/Siddhartha/Desktop/py scripts"
for item in os.listdir(root):
if not item.startswith('.') and os.path.isfile(os.path.join(root, item)):
print item
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With