shutil 模块

一、引入模块

  import shutil       #高级的 文件、文件夹、压缩包 处理模块

二、func 介绍

 1 import shutil
 2 
 3 # copy(src, dst);Copy data and mode bits ("cp src dst"). Return the file's destination.
 4 shutil.copy('pef.py', 'logs.log')
 5 
 6 # copy2(src, dst);Copy data and all stat info ("cp -p src dst"). Return the file's destination."
 7 shutil.copy2('pef.py', 'logs2.log')
 8 
 9 # copystat(src, dst, *, follow_symlinks=True); Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
10 shutil.copystat('pef.py', 'log.log')
11 
12 # copytree(src, dst, symlinks=False, ignore=None);Recursively copy a directory tree.
13 shutil.copytree('folder1', 'folder2', ignore=shutil.ignore_patterns('*.pyc', 'tmp*'))
14 
15 # make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0, dry_run=0, owner=None, group=None, logger=None)
16 # Create an archive file (eg. zip or tar).
17 # 将 C:\Users\xionggex\Desktop\ac_test\lib 下的文件打包放置 C:\Users\xionggex\Desktop\目录,lib2 为文件名
18 shutil.make_archive(r'C:\Users\xionggex\Desktop\lib2', 'gztar', root_dir=r'C:\Users\xionggex\Desktop\ac_test\lib')
19 # 将 /Users/wupeiqi/Downloads/test 下的文件打包放置当前程序目录,lib2 为文件名
20 shutil.make_archive('lib2', 'zip', root_dir=r'C:\Users\xionggex\Desktop\ac_test\lib')

 

posted @ 2018-09-05 16:41  Sky_Liao  阅读(157)  评论(0编辑  收藏  举报