栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python海量文件遍历

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python海量文件遍历

python zipfile

The ZIP file format is a common archive(文档/档案) and compression(压缩) standard. This module provides tools to create, read, write, append, and list a ZIP file.

想进一步了解可以点击链接查看

zipfile — Work with ZIP archives — Python 3.10.2 documentationhttps://docs.python.org/3/library/zipfile.html

python OS

This module provides a portable way of using operating system dependent functionality.

With this way,you can read or write a file and something about file.

python将数据集解压到目标文件
import zipfile #引入文件处理函数,便于文件解压缩
import os   #python提供的处理文件和目录的方法

#解压src_path路径下的数据到target_path路径下
def unzip_data(src_path,target_path):
    # 判断,如果target_path文件为空则执行如下操作
    if(not os.path.isdir(target_path)):
        读取该文件
        z = zipfile.ZipFile(src_path, 'r')   
        #将上一行代码中打开的源文件解压到目标文件目录
        z.extractall(path=target_path)
        z.close()



#调用函数
unzip_data()
zipfile.ZipFile()
# Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'

ZipFile.extractall(path=Nonemembers=Nonepwd=None)

Extract all members from the archive to the current working directory.

统计解压文件中所有子文件的名字和存储空间的大小

注意:代码的可复用与模块化

os.listdir()

Return a list containing the names of the files in the directory.

os.path.splitext(path)

Split the pathname path into a pair (root, ext) such that root + ext == path

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/755582.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号