From e5f00496a55b0ade233efb269696451a0990d1f3 Mon Sep 17 00:00:00 2001 From: KeksNino <87879013+KeksNino@users.noreply.github.com> Date: Sat, 27 Sep 2025 22:55:27 +0200 Subject: [PATCH] add deletion confirmation --- csv_file_sync.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/csv_file_sync.py b/csv_file_sync.py index afad712..29d467b 100644 --- a/csv_file_sync.py +++ b/csv_file_sync.py @@ -1,8 +1,17 @@ import os import csv -download_folder = "YOUR_FILE_DIRECTORY_PATH" +def confirm(prompt="Are you sure? (y/n): "): + while True: + ans = input(prompt).strip().lower() + if ans in ["y", "yes"]: + return True + elif ans in ["n", "no"]: + return False + else: + print("Please enter 'y' or 'n'.") +download_folder = "YOUR_FILE_DIRECTORY_PATH" csv_file = "YOUR_CSV_FILE_PATH" playlist_tracks = set() @@ -10,12 +19,13 @@ with open(csv_file, newline='', encoding='utf-8') as f: reader = csv.reader(f) for row in reader: row = row[:-1] - filename = f"{row[1]} - {row[0]}.mp3" + new_row = [cell.replace("/", "-") for cell in row] + filename = f"{new_row[1]} - {new_row[0]}.mp3" playlist_tracks.add(filename) # Scan download folder for file in os.listdir(download_folder): if file not in playlist_tracks: file_path = os.path.join(download_folder, file) - os.remove(file_path) - print(f"Deleted File: {file}") + if confirm(f"Delete {file}? (y/n): "): + os.remove(file_path)