-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntar_and_delete.py
51 lines (37 loc) · 1.27 KB
/
untar_and_delete.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'''
untar_and_delete.py
by Paul Mason ([email protected])
and Lisha Sterling ([email protected])
Does what it says on the tin.
Extracts tarballs from a specfied directory
into a directory of your choice.
Will remove tarballs after extraction if you want.
Uses python < 2.7
change raw_input() to input() for python >3.0
License: GNU Public License v.3
http://www.gnu.org/licenses/gpl.html
'''
import os
import sys
import re
import tarfile
path_to_tarballs = raw_input("Which directory holds the tarballs?")
def unzipthese(tarballs, delete):
extractTarPath = raw_input("What is the destination directory? ('.' is current directory)")
for tarball in tarballs:
extractThis = path_to_tarballs +"/"+ tarball
tfile = tarfile.open(extractThis)
tfile.extractall(extractTarPath)
if delete == "y" or delete == "Y":
print("Removing *"+ extractThis+"*")
os.remove(extractThis)
tarballs = []
dirEntries = os.listdir(path_to_tarballs)
for entry in dirEntries:
if re.match(".*\.tar\.gz", entry):
tarballs.append(entry)
print(entry)
unzip = raw_input("Unzip all?(y/N) ")
delete = raw_input("Delete tarballs after extraction? (y/N)")
if unzip == "y" or unzip == "Y":
unzipthese(tarballs, delete)