There's a file that I would like to make sure does not grow larger than 2 GB (as it must run on a system that uses ext 2). What's a good way to check a file's size bearing in mind that I will be writing to this file in between checks? In particular, do I need to worry about buffered, unflushed changes that haven't been written to disk yet?
Use os.path.getsize() function Use the os. path. getsize('file_path') function to check the file size. Pass the file name or file path to this function as an argument.
Using stat() from the os module, you can get the details of a file. Use the st_size attribute of stat() method to get the file size. The unit of the file size is byte .
Get file size in java using FileChannel class We can use FileChannel size() method to get file size in bytes.
Perhaps not what you want, but I'll suggest it anyway.
import os
a = os.path.getsize("C:/TestFolder/Input/1.avi")
Alternatively for an opened file you can use the fstat function, which can be used on an opened file. It takes an integer file handle, not a file object, so you have to use the fileno method on the file object:
a = open("C:/TestFolder/Input/1.avi")
b = os.fstat(a.fileno()).st_size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With