pretty size python 1

pretty size python

def human_size(bytes, units=[' bytes','KB','MB','GB','TB', 'PB', 'EB']):
    return str(bytes) + units[0] if bytes < 1024 else human_size(bytes>>10, units[1:])

Here is what the above code is Doing:
1. We’re using the os.walk() function to walk through the directory tree.
2. We’re using the os.path.join() function to join the current directory with the current file name.
3. We’re using the os.path.getsize() function to get the size of the current file.
4. We’re using the os.path.getmtime() function to get the last modified time of the current file.
5. We’re using the time.ctime() function to convert the last modified time to a human-readable format.
6. We’re using the human_size() function to convert the file size to a human-readable format.

Similar Posts