1.İşletim Sistemi = GNU/Linux Mint OS
Kod: Tümünü seç
============================================================
TARGETED FILE CLEANER | Cross-Platform Edition
OS: Linux | Python 3.12.3
============================================================
Enter the target directory path: /home/linuxmaster/Muzik/Albumler
Resolved path : /home/linuxmaster/Muzik/Albumler
Enter filenames to delete (comma-separated).
Example: Folder.jpg, AlbumArtSmall.jpg, Thumbs.db
Filenames: Folder.jpg, AlbumArtSmall.jpg
Target filenames (2):
- albumartsmall.jpg
- folder.jpg
Scanning... Please wait.
------------------------------------------------------------
Found 6 file(s) to delete:
/home/linuxmaster/Muzik/Albumler/Metallica - Black Album/Folder.jpg [142.3 KB]
/home/linuxmaster/Muzik/Albumler/Metallica - Black Album/AlbumArtSmall.jpg [18.7 KB]
/home/linuxmaster/Muzik/Albumler/Pink Floyd - The Wall/Folder.jpg [98.5 KB]
/home/linuxmaster/Muzik/Albumler/Pink Floyd - The Wall/AlbumArtSmall.jpg [21.1 KB]
/home/linuxmaster/Muzik/Albumler/Nirvana - Nevermind/Folder.jpg [110.0 KB]
/home/linuxmaster/Muzik/Albumler/Nirvana - Nevermind/AlbumArtSmall.jpg [19.4 KB]
Total size to free : 410.0 KB
------------------------------------------------------------
Proceed with deletion? [y/N]: y
------------------------------------------------------------
[DELETED] /home/linuxmaster/Muzik/Albumler/Metallica - Black Album/Folder.jpg
[DELETED] /home/linuxmaster/Muzik/Albumler/Metallica - Black Album/AlbumArtSmall.jpg
[DELETED] /home/linuxmaster/Muzik/Albumler/Pink Floyd - The Wall/Folder.jpg
[DELETED] /home/linuxmaster/Muzik/Albumler/Pink Floyd - The Wall/AlbumArtSmall.jpg
[ERROR] Permission denied: /home/linuxmaster/Muzik/Albumler/Nirvana - Nevermind/Folder.jpg
[DELETED] /home/linuxmaster/Muzik/Albumler/Nirvana - Nevermind/AlbumArtSmall.jpg
------------------------------------------------------------
Done. Deleted: 5 | Failed: 1
Press ENTER to exit.
Renk kodlaması şu anlama gelir:
Mavi → bölüm başlığı / ayraç
Açık mavi → kullanıcıdan istek
Turuncu → kullanıcının girdiği değerler ve dosya yolları
Yeşil → boyut bilgisi ve [DELETED] onayı
Kırmızı → [ERROR] (izin hatası örneği de ekledim )
2.İşletim Sistemi = Microsoft Windows OS - Windows Terminal - Windows PowerShell — targeted_file_cleaner.py -
Kod: Tümünü seç
PS C:\Users\commandwarrior>
python targeted_file_cleaner.py
============================================================
TARGETED FILE CLEANER | Cross-Platform Edition
OS: Windows | Python 3.12.3
============================================================
Enter the target directory path: C:\MUZIK\ALBUMLER
Resolved path : C:\MUZIK\ALBUMLER
Enter filenames to delete (comma-separated).
Example: Folder.jpg, AlbumArtSmall.jpg, Thumbs.db
Filenames: Folder.jpg, AlbumArtSmall.jpg
Target filenames (2):
- albumartsmall.jpg
- folder.jpg
Scanning... Please wait.
------------------------------------------------------------
Found 6 file(s) to delete:
C:\MUZIK\ALBUMLER\Metallica - Black Album\Folder.jpg [142.3 KB]
C:\MUZIK\ALBUMLER\Metallica - Black Album\AlbumArtSmall.jpg [18.7 KB]
C:\MUZIK\ALBUMLER\Pink Floyd - The Wall\Folder.jpg [98.5 KB]
C:\MUZIK\ALBUMLER\Pink Floyd - The Wall\AlbumArtSmall.jpg [21.1 KB]
C:\MUZIK\ALBUMLER\Nirvana - Nevermind\Folder.jpg [110.0 KB]
C:\MUZIK\ALBUMLER\Nirvana - Nevermind\AlbumArtSmall.jpg [19.4 KB]
Total size to free : 410.0 KB
------------------------------------------------------------
Proceed with deletion? [y/N]: y
------------------------------------------------------------
[DELETED] C:\MUZIK\ALBUMLER\Metallica - Black Album\Folder.jpg
[DELETED] C:\MUZIK\ALBUMLER\Metallica - Black Album\AlbumArtSmall.jpg
[DELETED] C:\MUZIK\ALBUMLER\Pink Floyd - The Wall\Folder.jpg
[DELETED] C:\MUZIK\ALBUMLER\Pink Floyd - The Wall\AlbumArtSmall.jpg
[DELETED] C:\MUZIK\ALBUMLER\Nirvana - Nevermind\Folder.jpg
[DELETED] C:\MUZIK\ALBUMLER\Nirvana - Nevermind\AlbumArtSmall.jpg
------------------------------------------------------------
Done. Deleted: 6 | Failed: 0
Press ENTER to exit. _
KOD İÇERİK :
Kod: Tümünü seç
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
targeted_file_cleaner.py
========================
Cross-platform targeted file remover.
Tested on: Windows 11, GNU/Linux Mint 22.x
"""
import os
import sys
import platform
from pathlib import Path
# ---------------------------------------------------------------------------
# VENV BOOTSTRAP
# ---------------------------------------------------------------------------
VENV_DIR = "/home/linuxmaster/python-toolchain"
def _bootstrap_venv():
_candidates = ["bin/python3", "bin/python", "Scripts/python.exe"]
for _rel in _candidates:
_exe = os.path.join(VENV_DIR, _rel)
if os.path.isfile(_exe) and os.access(_exe, os.X_OK):
if os.path.abspath(sys.executable) != os.path.abspath(_exe):
os.execv(_exe, [_exe] + sys.argv)
return
# venv not found -> run normally
if os.path.isdir(VENV_DIR):
_bootstrap_venv()
# ---------------------------------------------------------------------------
# CONFIGURATION
# ---------------------------------------------------------------------------
# System-protected root paths -- script will REFUSE to process these
PROTECTED_PATHS_WINDOWS = {
"c:\\windows",
"c:\\program files",
"c:\\program files (x86)",
"c:\\programdata",
"c:\\users\\default",
"c:\\system volume information",
"c:\\$recycle.bin",
"c:\\recovery",
}
PROTECTED_PATHS_LINUX = {
"/",
"/bin",
"/boot",
"/dev",
"/etc",
"/lib",
"/lib32",
"/lib64",
"/libx32",
"/media",
"/mnt",
"/opt",
"/proc",
"/root",
"/run",
"/sbin",
"/snap",
"/srv",
"/sys",
"/tmp",
"/usr",
"/var",
}
# ---------------------------------------------------------------------------
# HELPERS
# ---------------------------------------------------------------------------
def get_os_name() -> str:
return platform.system() # "Windows" | "Linux" | "Darwin"
def is_protected(target: Path) -> bool:
"""
Returns True if the target path is or resides inside a protected
system directory.
"""
os_name = get_os_name()
target_str = str(target).lower()
if os_name == "Windows":
protected = PROTECTED_PATHS_WINDOWS
# Also block bare drive roots: C:\, D:\, etc.
if len(target_str) <= 3 and target_str[1:] in (":\\", ":/", ":"):
return True
else:
protected = PROTECTED_PATHS_LINUX
# Block bare filesystem root
if target_str in ("/", ""):
return True
for p in protected:
if target_str == p or target_str.startswith(p + os.sep) or target_str.startswith(p + "/"):
return True
return False
def resolve_path(raw: str) -> Path:
"""
Expand ~, env vars and resolve to absolute path.
"""
expanded = os.path.expandvars(os.path.expanduser(raw.strip()))
return Path(expanded).resolve()
def print_separator(char: str = "-", width: int = 60):
print(char * width)
def human_size(num_bytes: int) -> str:
for unit in ("B", "KB", "MB", "GB"):
if num_bytes < 1024:
return f"{num_bytes:.1f} {unit}"
num_bytes /= 1024
return f"{num_bytes:.1f} TB"
# ---------------------------------------------------------------------------
# CORE LOGIC
# ---------------------------------------------------------------------------
def scan_files(base: Path, target_files: set) -> list[Path]:
"""
Walk the directory tree and collect files whose names match target_files.
Symbolic links are skipped for safety.
"""
found = []
for root, dirs, files in os.walk(base, followlinks=False):
for filename in files:
if filename.lower() in target_files:
full_path = Path(root) / filename
# Skip symlinks
if full_path.is_symlink():
print(f" [SKIP] Symlink ignored: {full_path}")
continue
found.append(full_path)
return found
def delete_files(file_list: list[Path]) -> tuple[int, int]:
"""
Delete each file in the list.
Returns (success_count, fail_count).
"""
success = 0
fail = 0
for f in file_list:
try:
f.unlink()
print(f" [DELETED] {f}")
success += 1
except PermissionError:
print(f" [ERROR] Permission denied: {f}")
fail += 1
except FileNotFoundError:
print(f" [WARN] Already gone: {f}")
fail += 1
except OSError as exc:
print(f" [ERROR] {f} -> {exc}")
fail += 1
return success, fail
# ---------------------------------------------------------------------------
# MAIN
# ---------------------------------------------------------------------------
def main():
print_separator("=")
print(" TARGETED FILE CLEANER | Cross-Platform Edition")
print(f" OS: {get_os_name()} | Python {sys.version.split()[0]}")
print_separator("=")
print()
# --- Get path from user ---
raw_input = input("Enter the target directory path: ").strip()
if not raw_input:
print("[ABORT] No path entered.")
input("\nPress ENTER to exit.")
sys.exit(1)
target_dir = resolve_path(raw_input)
print(f"\n Resolved path : {target_dir}")
print()
# --- Validate: exists and is a directory ---
if not target_dir.exists():
print(f"[ERROR] Path does not exist: {target_dir}")
input("\nPress ENTER to exit.")
sys.exit(1)
if not target_dir.is_dir():
print(f"[ERROR] Path is not a directory: {target_dir}")
input("\nPress ENTER to exit.")
sys.exit(1)
# --- Validate: not a protected system path ---
if is_protected(target_dir):
print(f"[BLOCKED] The path '{target_dir}' is a protected system location.")
print(" This script refuses to operate on system directories.")
input("\nPress ENTER to exit.")
sys.exit(1)
# --- Get target filenames from user ---
print("Enter filenames to delete (comma-separated).")
print("Example: Folder.jpg, AlbumArtSmall.jpg, Thumbs.db")
raw_files = input("Filenames: ").strip()
if not raw_files:
print("[ABORT] No filenames entered.")
input("\nPress ENTER to exit.")
sys.exit(1)
# Parse, lowercase, deduplicate
target_files = {
name.strip().lower()
for name in raw_files.split(",")
if name.strip()
}
if not target_files:
print("[ABORT] No valid filenames parsed.")
input("\nPress ENTER to exit.")
sys.exit(1)
print(f"\n Target filenames ({len(target_files)}):")
for name in sorted(target_files):
print(f" - {name}")
print()
# --- Scan ---
print("Scanning... Please wait.")
print_separator()
found_files = scan_files(target_dir, target_files)
if not found_files:
print("[INFO] No matching files found. Nothing to do.")
input("\nPress ENTER to exit.")
sys.exit(0)
# --- List what was found ---
total_size = 0
print(f"\nFound {len(found_files)} file(s) to delete:\n")
for f in found_files:
try:
size = f.stat().st_size
except OSError:
size = 0
total_size += size
print(f" {f} [{human_size(size)}]")
print()
print(f" Total size to free : {human_size(total_size)}")
print_separator()
# --- Confirmation ---
confirm = input("\nProceed with deletion? [y/N]: ").strip().lower()
if confirm not in ("y", "yes"):
print("[ABORT] Operation cancelled by user.")
input("\nPress ENTER to exit.")
sys.exit(0)
# --- Delete ---
print()
print_separator()
success, fail = delete_files(found_files)
print_separator()
print(f"\n Done. Deleted: {success} | Failed: {fail}")
print()
input("\nPress ENTER to exit.")
if __name__ == "__main__":
main()
Çapraz Desteklidir.Güle güle kullanın....
EKRAN GÖRÜNTÜSÜ