python statistics specified directory size

os Import
# statistics specified directory size
SUM = 0
DEF statistics_dir (dirpath):
    , Ltd. Free Join SUM
    # through all the files, to determine whether the file, the file size and cumulative statistics, directories recursively call, and returns the accumulated result
    for f in os.listdir (dirpath):
        ABSPATH = the os.path.join (dirpath, F)
        iF The os.path.isfile (ABSPATH): determines whether the file #
            SUM + = os.path.getsize (ABSPATH)
        elif os.path.isdir (ABSPATH ):
            statistics_dir (ABSPATH)
    return SUM


a_dir = input ( "Please enter the absolute path to the required directory statistics size:")
A = statistics_dir (a_dir)

print ( "size statistics is:" + str (a) + "bytes")
 

Released seven original articles · won praise 3 · Views 797

Guess you like

Origin blog.csdn.net/tttt0611/article/details/104593258