Created
February 8, 2017 07:54
-
-
Save xiaopeng163/4a909ef5d0d1845d11234d42880e64ca to your computer and use it in GitHub Desktop.
tar.gz file in a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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