The getsize() function is defined in the path sub-module of the os module. It is used to retrieve the file size in bytes of a given file or directory.

To use the function, we need to first import it in our program as follows.

from os.path import getsize
path The path to the file whose size we want.

 The path cen be absolute or relative to the working directory.

from os.path import getsize

p = r'C:\users\john\desktop\'

size = getsize(p)


If the path given does not exist, a FilenotFoundError exception will be raised. 

from os.path import getsize