python 搜索大文件的实例代码

yipeiwu_com6年前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()

以上这篇python 搜索大文件的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python深copy和浅copy区别对比解析

这篇文章主要介绍了python深copy和浅copy区别对比解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 首先先看一段代码...

Python编程中字符串和列表的基本知识讲解

Python 字符串 字符串是 Python 中最常用的数据类型。我们可以使用引号来创建字符串。 创建字符串很简单,只要为变量分配一个值即可。例如: var1 = 'Hello W...

python操作xml文件示例

复制代码 代码如下:def get_seed_data(filename):dom = minidom.parse(filename)root = dom.documentElement...

Python 实现OpenCV格式和PIL.Image格式互转

OpenCV转换成PIL.Image格式: import cv2 from PIL import Image import numpy img = cv2.imread("...

python中in在list和dict中查找效率的对比分析

首先给一个简单的例子,测测list和dict查找的时间: import time query_lst = [-60000,-6000,-600,-60,-6,0,6,60,600,6...