Python Program to List all the Files in a Directory with Size
destination source:https://www.programming-techniques.com/?p=2239
In this example, we will write a python program to get the size of the files inside a directory. To better understand this example, make sure you have knowledge of the following tutorials:-
The code for the program is as below:-
1 2 3 4 5 6 7 8 9 10 | import os def file_size(fname): info = os.stat(fname) return info.st_size for root, dirs, files in os.walk("."): for filename in files: print(filename + ' : ' + str(file_size(filename)) + " bytes") |
The output of the above program is:-
test.py : 278 bytes
about.txt : 293 bytes
hello.txt : 81 bytes
Related Article
destination source:https://www.programming-techniques.com/?p=2239