This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BookConverter/src/util/check_dirs.py
2022-08-03 16:44:23 +03:00

33 lines
916 B
Python

import os
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="Utility for folders's clean up.")
parser.add_argument("-f", "--folders", type=str, nargs="*", help="Names of the folders to be cleaned.")
args = parser.parse_args()
return args
def check_dir(dir_path: str):
if not os.path.exists(dir_path):
try:
os.mkdir(dir_path)
except OSError as exc:
raise exc
if __name__ == "__main__":
folders = parse_args().folders
if not folders:
folders = ["books/epub", "books/docx", "books/html", "books/json", "logs", "config"]
folder_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
folders = [os.path.join(folder_path, folder) for folder in folders]
try:
[check_dir(folder) for folder in folders]
except OSError as exc:
print(exc)
raise