diff --git a/1-Clean-Downloads.py b/1-Clean-Downloads.py index 6f46a59..5f7f418 100644 --- a/1-Clean-Downloads.py +++ b/1-Clean-Downloads.py @@ -11,6 +11,8 @@ def clean_downloads(folder_path, days=30): if os.path.isfile(file_path): file_mtime = datetime.fromtimestamp(os.path.getmtime(file_path)) if file_mtime < threshold: + if not os.path.exists(os.path.join(folder_path, "Archive")): + os.makedirs(os.path.join(folder_path, "Archive")) shutil.move(file_path, os.path.join(folder_path, "Archive", filename)) -clean_downloads("/path/to/your/downloads") \ No newline at end of file +clean_downloads(r"/path/to/your/downloads") diff --git a/3-Convert-CSV-to-Excel.py b/3-Convert-CSV-to-Excel.py index b292f22..6dcd5c7 100644 --- a/3-Convert-CSV-to-Excel.py +++ b/3-Convert-CSV-to-Excel.py @@ -14,4 +14,4 @@ def csv_to_excel_folder(folder_path): except Exception as e: print(f"Failed to convert {csv_file}: {e}") -csv_to_excel_folder("/path/to/your/folder") \ No newline at end of file +csv_to_excel_folder(r"/path/to/your/folder") diff --git a/4-Organize-Files.py b/4-Organize-Files.py index ff85fca..a1cb1e8 100644 --- a/4-Organize-Files.py +++ b/4-Organize-Files.py @@ -3,9 +3,32 @@ def organize_files(folder_path): for filename in os.listdir(folder_path): - ext = filename.split('.')[-1] + # 1. Full path of the item + item_path = os.path.join(folder_path, filename) + + # 2. Skip if it's a directory (or the script itself) + if os.path.isdir(item_path): + continue + + # 3. Determine the extension + if '.' in filename: + # For files with an extension (e.g., 'document.pdf' -> 'PDF') + ext = filename.split('.')[-1] + if len(ext) > 5: # Added to prevent very long strings from becoming folders + ext = "OTHER_FILES" + else: + # For files without an extension (e.g., 'README') + ext = "NO_EXTENSION" + + # 4. Create the destination folder path ext_folder = os.path.join(folder_path, ext.upper()) + + # 5. Create the folder (exist_ok=True is correct here) os.makedirs(ext_folder, exist_ok=True) - shutil.move(os.path.join(folder_path, filename), os.path.join(ext_folder, filename)) + + # 6. Move the file + shutil.move(item_path, os.path.join(ext_folder, filename)) -organize_files("/path/to/your/folder") \ No newline at end of file +# Example usage (uncommented): +# organize_files(r"C:\Users\vinaygandhi\Downloads") +organize_files(r"/path/to/your/folder") diff --git a/5-Batch-Rename-Files.py b/5-Batch-Rename-Files.py index cb82263..ec5aabf 100644 --- a/5-Batch-Rename-Files.py +++ b/5-Batch-Rename-Files.py @@ -6,4 +6,4 @@ def rename_files(folder_path, prefix): new_name = f"{prefix}_{count}.{ext}" os.rename(os.path.join(folder_path, filename), os.path.join(folder_path, new_name)) -rename_files("/path/to/your/folder", "Document") \ No newline at end of file +rename_files(r"/path/to/your/folder", "Document") diff --git a/Picture_cleanup.py b/Picture_cleanup.py new file mode 100644 index 0000000..e5cd93e --- /dev/null +++ b/Picture_cleanup.py @@ -0,0 +1,66 @@ +import os +import shutil + +# ====== CONFIG ======= +ROOT = "" # change this +KEEP_FORMAT = "heic" # "heic" or "jpeg" +DUP_DIR = os.path.join(ROOT, "duplicates") +# ====================== + +os.makedirs(DUP_DIR, exist_ok=True) + +# Normalize known extensions +JPEG_EXTS = {".jpg", ".jpeg"} +HEIC_EXTS = {".heic"} + +files_map = {} + +# Scan folder +for file in os.listdir(ROOT): + full = os.path.join(ROOT, file) + if not os.path.isfile(full): + continue + + name, ext = os.path.splitext(file.lower()) + + if ext in JPEG_EXTS or ext in HEIC_EXTS: + if name not in files_map: + files_map[name] = [] + files_map[name].append(file) + +# Detect duplicates and move +for base, variants in files_map.items(): + if len(variants) < 2: + continue # no duplicates + + has_jpeg = any(v.lower().endswith(tuple(JPEG_EXTS)) for v in variants) + has_heic = any(v.lower().endswith(tuple(HEIC_EXTS)) for v in variants) + + # Only process jpeg+heic pairs + if not (has_jpeg and has_heic): + continue + + print(f"Duplicate set found: {variants}") + + # Determine which to keep + keep_file = None + remove_file = None + + if KEEP_FORMAT == "heic": + keep_file = next(v for v in variants if v.lower().endswith(".heic")) + remove_file = next(v for v in variants if v.lower().endswith(tuple(JPEG_EXTS))) + else: + keep_file = next(v for v in variants if v.lower().endswith(tuple(JPEG_EXTS))) + remove_file = next(v for v in variants if v.lower().endswith(".heic")) + + print(f"Keeping: {keep_file}") + print(f"Removing: {remove_file}") + + # Move duplicate to duplicates/ + shutil.move( + os.path.join(ROOT, remove_file), + os.path.join(DUP_DIR, remove_file) + ) + +print("\nDone! Check the 'duplicates' folder.") +