用python获取linux下一个目录下一级目录的各自大小

#!/bin/env python
# _*_coding:UTF-8 _*_

import sys
import os
from os.path import join,getsize

pathd = sys.argv[1]

def filesize(path):
        files = os.listdir(path)
        size = 0
        for fi in files:
                pa = path  +fi
                if os.path.isdir(pa):
                        pao = pa + '/'
                        size += filesize(pao)
                else:
                        size += getsize(pa)
        return size


files = os.listdir(pathd)
for fi in files:
        new_pa = pathd + fi
        if os.path.isdir(new_pa):
                pa = new_pa + '/'
                new_size = filesize(pa)
                print  '%s ---------------size--------->:%d' %(pa,new_size)

        else:
                continue

 

转载于:https://my.oschina.net/u/2313186/blog/719359

你可能感兴趣的:(用python获取linux下一个目录下一级目录的各自大小)