python之shutil

 

'''
shutil
用來處理 文件 文件夾 壓縮包 的模塊
'''

import shutil

# 拷貝文件內容
shutil.copyfileobj(open('old.xml', 'r'), open('new.xml', 'w'))

# 拷貝文件
shutil.copyfile('f1.log', 'f2.log')

# 拷貝權限
shutil.copymode('f1.log', 'f2.log')

# 拷貝文件狀態信息
shutil.copystat('f1.log', 'f2.log')

# 拷貝文件和權限
shutil.copy('f1.log', 'f2.log')

# 遞歸地拷貝文件夾
# shutil.copytree('folder1', 'folder2',
ignore=shutil.ignore_patterns('*.pyc', '*.txt'))

# 遞歸地刪除文件
# shutil.rmtree('folder2')

# 遞歸地移動重命名文件
# shutil.move('folder2', 'folder3')

# 打包文件
ret = shutil.make_archive(r'C:\GitHub\Python\day7\shutil\www', 'gztar',
root_dir=r'C:\GitHub\Python\day7\shutil\folder1')
相關文章
相關標籤/搜索