Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 1-Clean-Downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
clean_downloads(r"/path/to/your/downloads")
2 changes: 1 addition & 1 deletion 3-Convert-CSV-to-Excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
csv_to_excel_folder(r"/path/to/your/folder")
29 changes: 26 additions & 3 deletions 4-Organize-Files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
# Example usage (uncommented):
# organize_files(r"C:\Users\vinaygandhi\Downloads")
organize_files(r"/path/to/your/folder")
2 changes: 1 addition & 1 deletion 5-Batch-Rename-Files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
rename_files(r"/path/to/your/folder", "Document")
66 changes: 66 additions & 0 deletions Picture_cleanup.py
Original file line number Diff line number Diff line change
@@ -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.")