If there will be a small number of files it should be easy with a recursive function to pass through all the files and add the size but what if there are lots of files, and by lots i really mean lots of files.
How to view the file size of a directory. To view the file size of a directory pass the -s option to the du command followed by the folder. This will print a grand total size for the folder to standard output.
Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).
You can view folder size in Windows using one of below options. In File explorer, right click on folder for which you want to see folder size, and click on "Properties" in context menu. This will display folder properties dialog showing folder size in "Size" and "Size on disk" display field.
Use os.path.getsize() function getsize('file_path') function to check the file size. Pass the file name or file path to this function as an argument.
You mean something like this?
import os
for path, dirs, files in os.walk( root ):
for f in files:
print path, f, os.path.getsize( os.path.join( path, f ) )
There is no other way to compute the size than recursively invoking stat. This is independent of Python; the operating system just provides no other way.
The algorithm doesn't have to be recursive; you can use os.walk.
There might be two exceptions to make it more efficient:
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