-
Notifications
You must be signed in to change notification settings - Fork 5
/
retrieve_file.py
28 lines (22 loc) · 937 Bytes
/
retrieve_file.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
import os
import argparse
import subprocess as sp
def main(tag, inn_dir, output):
if inn_dir.startswith('./'):
inn_dir = inn_dir[2:]
r = []
for dir_path, _, file_list in os.walk(inn_dir):
for file_name in file_list:
fp = os.path.join(dir_path, file_name)
if tag in file_name:
r.append(fp)
if not output.endswith('.7z'):
output += '.7z'
sp.call(['7z', 'a', output, '-spf'] + r)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Retrieve all file with tag into .7z')
parser.add_argument('-i', '--input', required=True, help='target directory to search')
parser.add_argument('-t', '--tag', required=True, help='tag need to be contained in file name')
parser.add_argument('-o', '--output', required=True, help='name of output .7z file')
args = parser.parse_args()
main(args.tag, args.input, args.output)