# -*- coding: utf-8 -*-
"""
Created on Tue Nov 27 10:52:57 2018
"""
Created on Tue Nov 27 10:52:57 2018
@author: issta
"""
"""
import os
import tarfile
__author__ = 'Administrator'
import tarfile
__author__ = 'Administrator'
RelativeOrAbsoluteTar = True #False
def archive():
cwd = os.getcwd()
tar = tarfile.open('IsstaGao'+".tar.gz", 'w:gz')
for root, dirs, files in os.walk(cwd):
for file in files:
fullpath = os.path.join(root,file)
if RelativeOrAbsoluteTar :
used_path = os.path.relpath(fullpath, start=os.curdir)
#relative_path = os.path.relpath(fullpath, start = cwd)
else :
used_path = fullpath
tar.add(used_path)
tar.close()
if __name__=='__main__':
archive()
def archive():
cwd = os.getcwd()
tar = tarfile.open('IsstaGao'+".tar.gz", 'w:gz')
for root, dirs, files in os.walk(cwd):
for file in files:
fullpath = os.path.join(root,file)
if RelativeOrAbsoluteTar :
used_path = os.path.relpath(fullpath, start=os.curdir)
#relative_path = os.path.relpath(fullpath, start = cwd)
else :
used_path = fullpath
tar.add(used_path)
tar.close()
if __name__=='__main__':
archive()
------------------运行结果: