Skip to main content

Delete files in a directory tree matching a glob pattern, dry run first.

Project description

1. Environment

  • Python 3.14.6
  • pip 26.1.2

2. Installation

$ pipx install spreen-clean

(pip install spreen-clean works too if you prefer managing the environment yourself.)

For development, install the dependencies via requirements.txt:

$ pip install -r requirements.txt

3. Execution

$ file-clean '*.log' --dirname ./tmp
Target dirname is /home/hayat01sh1da/workspace/tmp
========== [DRY RUN] Total File Count to Clean: 2 ==========
========== [DRY RUN] Start Cleaning *.log ==========
========== [DRY RUN] Cleaning ./tmp/app.log ==========
========== [DRY RUN] Cleaning ./tmp/jobs/worker.log ==========
========== [DRY RUN] Cleaned *.log ==========
========== [DRY RUN] Total Cleaned File Count: 2 ==========

The dry run above is the default. Once the list looks right, execute the deletion with --mode e (this cannot be undone):

$ file-clean '*.log' --dirname ./tmp --mode e
Target dirname is /home/hayat01sh1da/workspace/tmp
========== [EXECUTION] Total File Count to Clean: 2 ==========
========== [EXECUTION] Start Cleaning *.log ==========
========== [EXECUTION] Cleaning ./tmp/app.log ==========
========== [EXECUTION] Cleaning ./tmp/jobs/worker.log ==========
========== [EXECUTION] Cleaned *.log ==========
========== [EXECUTION] Total Cleaned File Count: 2 ==========

With no arguments, file-clean dry-runs every file under the current directory (PATTERN defaults to *, --dirname to .).

Two guardrails back the dry-run default: a dirname resolving to a filesystem root (/, C:\, ...) is refused before anything is scanned, and when the execution mode matches more than 100 files the CLI asks for an explicit y first — pass --yes to skip the prompt in scripts:

$ file-clean '*.log' --dirname ./tmp --mode e
About to delete 101 files (more than 100). Type `y` to proceed: n
Aborted the execution mode without deleting anything.

As a library:

from spreen_clean import Application

Application.run(dirname='./tmp', pattern='*.log')            # dry run
Application.run(dirname='./tmp', pattern='*.log', mode='e')  # execute

# The progress log goes to stdout by default; pass any text stream to capture it.
import io
stream = io.StringIO()
Application.run(dirname='./tmp', pattern='*.log', io=stream)
stream.getvalue()  # => 'Target dirname is ...\n========== [DRY RUN] ...'

4. Unit Test

$ pytest
============================= test session starts ==============================
platform linux -- Python 3.14.6, pytest-9.1.1, pluggy-1.6.0
rootdir: spreen-clean/PyPI
configfile: pyproject.toml
collected 17 items

test/test_application.py ........                                        [ 47%]
test/test_cli.py .........                                               [100%]

============================== 17 passed in 0.42s ===============================

5. Static Code Analysis

$ flake8 .
$ autoflake8 --in-place --remove-duplicate-keys --remove-unused-variables --recursive .
$ autopep8 --in-place --aggressive --aggressive --recursive .

6. Type Checks

$ mypy .
Success: no issues found in 6 source files

7. Build

$ python -m build
$ pipx install ./dist/spreen_clean-0.1.0-py3-none-any.whl

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spreen_clean-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spreen_clean-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file spreen_clean-0.1.0.tar.gz.

File metadata

  • Download URL: spreen_clean-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for spreen_clean-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1862db13e0a14439070aef6a66dc33ea65a2d8b333e4c1ce466953c99b18316a
MD5 806390dee54fb9d16a944d8e76a054af
BLAKE2b-256 f34eba443e7b82015f6c13d6b2c32c9c5397c4cf8d6c8eb10d348ca79bde1f3a

See more details on using hashes here.

File details

Details for the file spreen_clean-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spreen_clean-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for spreen_clean-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c3aa0232ae7210c8e808ca9986cdb8f59baba61e12c9c4d62b86eba2d68430d
MD5 b38958f16776549def19b7b13da4fab6
BLAKE2b-256 a69d563836700c6f42131e87a2123d4ea22b7750dd064204aa2c9d03006a5bca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page