forked from facebookresearch/dinov2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
untar_archives.py
35 lines (30 loc) · 1 KB
/
untar_archives.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
import glob
import os
import shutil
import sys
import tarfile
from argparse import ArgumentParser
from pathlib import Path
def untar_archives(input_path: Path, output_path: Path):
archives = glob.glob(str(input_path / '*.tar.gz'))
for archive in archives:
tar = tarfile.open(input_path / archive, "r:gz")
tar.extractall(output_path)
tar.close()
parser = ArgumentParser(
description="Untar archive files from input path to output path")
parser.add_argument("--input_path",
type=str,
required=True,
help="Input path to search for archives")
parser.add_argument(
"--output_path",
type=str,
required=False,
default=None,
help="output path to save extracted archives, default to input path")
if __name__ == "__main__":
args = parser.parse_args()
input_path = Path(args.input_path)
output_path = Path(args.output_path) if args.output_path else input_path
untar_archives(input_path, output_path)