Finding empty files in Python
What's the best way in Python to find all empty (zero byte) files, recursively, from a given directory? I could use os.walk and stat each fi开发者_Go百科le, but that seems very inefficient. Thanks.
I'm not sure how you'd get more efficient than os.walk
and stat
since that's fundamentally what you're doing. You could use some external command/service through Python's subprocess.Popen
but then that's hardly "in python".
First, you should make it work, then figure out how to make it faster. You shouldn't start with a feeling that the most obvious way "seems very inefficient" If you want efficient, you can try the native OS.
os.system("find . -empty")
精彩评论