DEV Community

Basha
Basha

Posted on

How to get the size a file or folder in bytes

It is extremely easy to get the size of a file in python.

import os
if os.path.isdir(file_dr):
   size = str(get_size(file_dr))

else:

   size = str(os.path.getsize(file_dr))
print(size)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)