Skip to content

Instantly share code, notes, and snippets.

@ruofeidu
Created December 30, 2025 20:08
Show Gist options
  • Select an option

  • Save ruofeidu/a4baaa783cd61a7eb382218a56b7258c to your computer and use it in GitHub Desktop.

Select an option

Save ruofeidu/a4baaa783cd61a7eb382218a56b7258c to your computer and use it in GitHub Desktop.
"""Module to recursively delete Sony RAW (.ARW) files from a directory."""
import logging
from pathlib import Path
def delete_arw_files(target_dir: str = "."):
"""Recursively finds and removes all files with the .arw extension.
Args:
target_dir: The root directory to start searching from. Defaults to the
current working directory.
"""
root_path = Path(target_dir).resolve()
# Uses rglob to find all files ending in .arw case-insensitively.
# Note: rglob is recursive by default.
for file_path in root_path.rglob("*"):
if file_path.suffix.lower() == ".arw":
try:
# Deletes the file from the filesystem.
file_path.unlink()
print(f"Deleted: {file_path}")
except OSError as e:
# Handles specific filesystem errors like permission issues.
logging.error("Failed to delete %s: %s", file_path, e)
if __name__ == "__main__":
delete_arw_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment