-
Notifications
You must be signed in to change notification settings - Fork 0
/
targz_files
executable file
·32 lines (25 loc) · 962 Bytes
/
targz_files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
"""
tar.gz files in a directory.
"""
import os
import argparse
parser = argparse.ArgumentParser(description="""
Compress files in a directory.""",
formatter_class = lambda prog:
argparse.HelpFormatter(prog, max_help_position=40))
parser.add_argument("DIRECTORY",
help=('Directory to search for files.'))
args = parser.parse_args()
DIRECTORY = args.DIRECTORY
#-----------------------------------------------------------------------------
# Start walking through the directory tree from start_path:
#-----------------------------------------------------------------------------
items = os.listdir(DIRECTORY)
for item in items:
filename = os.path.join(DIRECTORY, item)
compressed = filename + ".tar.gz"
if not os.path.exists(compressed):
cmd = 'tar cvfz {0} {1}'.format(compressed, filename)
print(cmd)
os.system(cmd)