I am writing a Python script in Windows. I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things.
How do I check the file size?
I am writing a Python script in Windows. I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things.
How do I check the file size?
Using
pathlib
(added in Python 3.4 and available on PyPI)...This is really only an interface around
os.stat
, but usingpathlib
provides an easy way to access other file related operations.There is a
bitshift
trick I use if i want to to convert frombytes
to any other unit. If you do a right shift by10
you basically shift it by an order (multiple).