```python
import os
import glob
import time
import datetime
# from tempfile import Temporaryfile
#
# with Temporaryfile('w+') as f:
# f.write('hello')
# f.seek(0)
# date = f.readlines()
# print(date)
# os.mkdir('新建文件夹')
#批量创建十个txt文件
# for i in range(10):
# f=open("%s"%i+'.txt','a')
# #./ 代表是当前的文件夹,%i表示文件的名称,a表示没有改文件夹就新建
#
# f.write("")
# f.close()
# 批量创建5 个文件夹
# import os
# #设置文件夹的位置
# path = '.dar1/'
# for i in range (5):
# #定义一个变量判断文件是否存在。
# isExists = os.path.exists(path+str(i))
# if not isExists:
# os.makedirs(path+str(i))
# print("%s目录创建成功"%i)
# else:
# print("%s目录已经存在"%i)
# continue
# 复制文件和文件夹
# import shutil
# # shutil.copy(要复制的文件,要复制到的文件)
# # 文件夹
# # 路径复制并重命名
# shutil.copy('file2.txt','./a1') #复制
# shutil.copy('file2.txt','./a1/file3.txt')#复制并重命名
# 复制文件夹shutil.copytree()
# shutil.copytree('a1','./a1/a2')
# # 移动 重名 和删除
# import shutil
# shutil.move("2.txt","./a1")#移动文件
# os.rename("1.txt","0.txt") #重命名文件和文件夹
# os.remove('0.txt') #删除文件
# shutil.rmtree("a2")#删除目录
#读取压缩包内文件
#zipfile --后缀为zip的文件
# import zipfile
# with zipfile.Zipfile("a0.zip","r") as zipobj:
# for filename in zipobj.nameList():
# print(filename)
#如何解决压缩名为中文的文件会出现乱码的问题
# import zipfile枣庄人流医院排行榜 http://mobile.3635555.cn/
# with zipfile.Zipfile("学习文件.zip","r") as zipobj:
# for filename in zipobj.nameList():
# print(filename.encode("cp437").decode("gbk"))
# #创建zip压缩包
# import zipfile
# with zipfile.Zipfile("x1.zip","w") as zipobj:
# zipobj.write("0.txt")
# # 批量文件创建压缩包
# file_name = ["0.txt","1.txt","2.txt","3.txt"]
# with zipfile.Zipfile("x1.zip","w") as zipobj:
# for filen in file_name:
# zipobj.write(filen)
# # 读取压缩包文件
# with zipfile.Zipfile("x1.zip","r") as zipobj:
# print(zipobj.nameList())
#
# file_name = ["4.txt","5.txt","6.txt","7.txt"]
# with zipfile.Zipfile("x1.zip","a") as zipobj:
# for filen in file_name:
# zipobj.write(filen)
# # 读取压缩包文件
# with zipfile.Zipfile("x1.zip","r") as zipobj:
# print(zipobj.nameList())
#解压文件
# import zipfile
# with zipfile.Zipfile("a0.zip","r") as zipobj :
# zipobj.extractall("./a2")
# # zipobj.extractall("./a2",pwd='123456')
总结以上是内存溢出为你收集整理的用Python关于 文件的复制移动压缩解压全部内容,希望文章能够帮你解决用Python关于 文件的复制移动压缩解压所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)