Skip to content

Instantly share code, notes, and snippets.

@xiaopeng163
Created February 8, 2017 07:54
Show Gist options
  • Save xiaopeng163/4a909ef5d0d1845d11234d42880e64ca to your computer and use it in GitHub Desktop.
Save xiaopeng163/4a909ef5d0d1845d11234d42880e64ca to your computer and use it in GitHub Desktop.
tar.gz file in a folder
import os
import tarfile
MSG_PATH = './'
file_list = os.listdir(MSG_PATH)
for msg_file in file_list:
if not msg_file.endswith('.msg'):
continue
tar_file_name = os.path.join(MSG_PATH, msg_file) + '.tar.gz'
tar = tarfile.open(tar_file_name, "w:gz")
tar.add(os.path.join(MSG_PATH, msg_file))
tar.close()
os.remove(os.path.join(MSG_PATH, msg_file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment