From 76e72db446426eaa45f6ec543011f2a6804f77eb Mon Sep 17 00:00:00 2001 From: rouggy Date: Wed, 26 Jan 2022 20:04:26 +0700 Subject: [PATCH] update --- filebot.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/filebot.py b/filebot.py index 6b670f9..98ba673 100644 --- a/filebot.py +++ b/filebot.py @@ -3,7 +3,6 @@ from glob import glob import shutil import os -from pathlib import Path import subprocess import re @@ -17,23 +16,15 @@ dest_path = "C:/Test/PostProcess" print("Checking if rar files and unraring...") -for root, dirs, files in os.walk(source_path): - for dir in dirs: - for file in files: - rar_file = glob(f"{os.path.join(root, '')}*rar") +for section in section_folders: + if os.path.exists(os.path.join(source_path, section)): + for dir in os.listdir(os.path.join(source_path, section)): + rar_file = glob(f"{os.path.join(source_path, section, dir, '')}*rar") if rar_file: print(f"Found rar file {rar_file}") - subprocess.run(["/usr/bin/unrar", 'e', rar_file[0], '-idq', '']) + # subprocess.run(["/usr/bin/unrar", 'e', rar_file[0], '-idq', '']) -print("Deleting rar, sfv, nfo files...") -for root, dirs, files in os.walk(source_path): - for dir in dirs: - if re.search('sample', dir, re.IGNORECASE) or re.search('proof', dir, re.IGNORECASE): - shutil.rmtree(os.path.join(root, dir)) - -for root, dirs, files in os.walk(source_path): - for dir in dirs: - if dir not in section_folders: - match = re.search(r'.*\/(.*)', root) - section_path = match.group(1) - shutil.move(os.path.join(root, dir), os.path.join(dest_path, section_path)) \ No newline at end of file +for section in section_folders: + if os.path.exists(os.path.join(source_path, section)): + for dir in os.listdir(os.path.join(source_path, section)): + shutil.move(os.path.join(source_path, section, dir), os.path.join(dest_path, section))