python
主页 > 脚本 > python >

python 搜索大文件的方法

2019-07-09 | 秩名 | 点击:
本篇文章介绍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()


原文链接:https://blog.csdn.net/CosmopolitanMe/article/details/79921349
相关文章
最新更新