2808 explained code solutions for 75 technologies


pythonCalculate the size of directory in bytes


python -c "import os;print(sum(os.path.getsize(f) for f in os.listdir('.') if os.path.isfile(f)), 'bytes')"ctrl + c
-c

flag allows the execution of statements following the flag

import os

use os module

os.listdir('.')

list all contents of current directory

os.path.isfile(f)

determine if f is a file

os.path.getsize(f)

get size of file f