I am writing a python script in windows. I want to do something based on the file size. For example, if size greater than 0, i will send email to somebody, otherwise continue to other things. so how to check file size? thanks
+6
A:
Like this (credit http://www.daniweb.com/forums/thread78629.html):
>>> import os
>>> b = os.path.getsize("/path/isa_005.mp3")
>>> b
2071611L
danben
2010-01-20 18:59:16
+7
A:
Use os.stat, and use the st_size member of the resulting structure:
>>> import os
>>> statinfo = os.stat('somefile.txt')
>>> statinfo
(33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 1105022732)
>>> statinfo.st_size
926L
Adam Rosenfield
2010-01-20 19:01:53