python搜索大文件

import os,os.path

def     getBigFile(pathname,filesize):#第一个参数为要遍历的文件夹,第二个是要找的最小文件的大小
        fileList = []
        for root,dirs,files in os.walk(pathname):#这里os.walk()遍历目录
            for file in files:
                fname = os.path.abspath(os.path.join(root,file))
                if os.path.getsize(fname)>filesize:
                    fileList.append(fname)#加入到找到文件的列表里
        return fileList

def     main():

        getBigFile("G:",300*1024*1024)#寻找G盘所有大于300MB的文件
if      __name__=="__main__":
        main()

猜你喜欢

转载自blog.csdn.net/cosmopolitanme/article/details/79921349