-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_filetype.py
56 lines (42 loc) · 1.48 KB
/
check_filetype.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
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import argparse
from re import match
from typing import List
def get_parser() -> argparse.ArgumentParser: # parses flags in command
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter, description="",
epilog="""
Made by Aaron Earle-Richardson (ae166@duke.edu)
""")
parser.add_argument("-d", "--directory", required=True, default=None,
help="""
Input data directory
""")
parser.add_argument("-t", "--ext", required=True, default=None,
help="File type")
return parser
def list_subdir(folder: str) -> List[str]:
out_files = []
for root, _, files in os.walk(folder):
for file in files:
out_files.append(os.path.join(root, file))
return out_files
def check_ext(filename: str, ext: str) -> bool:
out = filename.lower().endswith(ext)
return out
def main(directory: str, ext: str):
out: List[str] = []
dirs = os.listdir(directory)
for pat in dirs:
folder = os.path.join(directory, pat)
if match("^D\\d{2}", pat) and os.path.isdir(folder):
if not any([check_ext(file, ext) for file in list_subdir(folder)]):
out.append(pat)
return out
if __name__ == "__main__":
args = get_parser().parse_args()
print(os.path.basename(vars(args)['directory']))
for item in main(**vars(args)):
print(item)