Python基础-shutil模块
高级的 文件、文件夹、压缩包 处理模块
使用方法如下:
import shutil
# shutil.copyfileobj(open('sheve_test.py', 'r', encoding='utf-8'), open('sheve_test_new.py', 'w'))
# shutil.copyfile('f1.log', 'f2.log')
# shutil.copymode('f1.log', 'f2.log')
# shutil.copystat('f1.log', 'f2.log')
# shutil.copy("f1.log", "f3.log")
# shutil.copy2('f1.log', 'f4.log')
# shutil.copytree("packages", "pack4", ignore=shutil.ignore_patterns("__init__.py", "views.py"))
# shutil.rmtree("pack4")
# shutil.move("pack3", "p3")
# shutil.make_archive("package_bak", "zip")
import zipfile
# z = zipfile.ZipFile('laxi.zip', 'w')
# z.write('f1.log')
# z.write('f2.log')
# z.write('f3.log')
#
# z.close()
# z = zipfile.ZipFile('laxi.zip', 'r')
# z.extractall(path='..')
# z.close()
import tarfile
# t = tarfile.open('xu.tar', 'w')
# t.add('f1.log')
# t.add('f2.log')
# t.add('f3.log')
# t.close()
t = tarfile.open('xu.tar', 'r')
t.extractall('..')
t.close()