Skip to main content

CLI tool to copy and rename files starting with ! to multiple destinations.

Project description

Bang Logo

Bang File Copier (CLI Tool)


Overview

Bang File Copier is a lightweight command-line tool written in Python that scans a given directory for files whose names start with an exclamation mark (!), then copies those files into one or more predefined destination directories. During the copy process, each file is renamed by prefixing it with the source folder’s name.

I use this tool for my personal photography workflow. After each shoot, I manually review the photos and mark the best ones by adding one or more exclamation marks (!) at the start of the filename. This tool then automates the next step by finding those marked files and copying them into the folders I use for retouching and publishing.

Bang Screenshot


Development Method

This project was developed in an iterative AI-assisted workflow:

  1. I first explained my project goal to an AI tool.
  2. The AI generated a more complete project explanation.
  3. I reviewed and edited that explanation multiple times until it was ready for README.md.
  4. I then asked the AI to generate a step-by-step development plan, which it saved in produce_steps.md.
  5. In my free time, I asked the AI to implement each step progressively.
  6. After each implementation step, I reviewed the generated code and edited it when needed.
  7. Finally, I completed the final fixes and refinements, then updated the README sections.

Tools used in this process:

  • VSCode (editing and project work)
  • ChatGPT (project explanation and documentation drafting)
  • Copilot CLI (code generation and implementation support)

Dependencies

Required

  • Python 3.8+

Optional

  • rich – Pretty console output with tables, panels, and styled text
  • pyfiglet – ASCII art text rendering (used for the intro banner)

Both optional dependencies serve UI enhancement only. The tool will fall back to plain text output if they are unavailable.


Packaging & Installation

1. Create an isolated Python environment (recommended)

Using pyenv + venv keeps your global Python clean and avoids dependency conflicts.

pyenv install 3.11.11   # one-time (if not already installed)
pyenv local 3.11.11
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip

2. Install from PyPI (recommended for normal use)

pip install bang-file-copier

This installs the latest published version and exposes the bang CLI command.

3. Install from source (development)

Install in editable mode from the project root:

pip install -e .

This installs the dependencies and exposes the bang CLI command from [project.scripts].

4. Run the tool

Use the installed CLI:

bang [path] [--dry-run]

Or run it as a Python module:

python -m bang_file_copier [path] [--dry-run]

Core Features

1. Folder Scanning

  • Accepts a target directory path as input (either explicitly or defaults to the current working directory).

  • Scans only the top-level of the directory (no recursion in v1).

  • Identifies files that:

    • Are regular files (not directories)
    • Have names starting with ! (e.g., !photo1.jpg, !note.txt)

2. File Copying to Two Destinations

  • Copies all matched files into two destination directories.

  • Destination directories are:

    • Read from a configuration file (e.g., config.json or config.yaml)
    • Or fallback to hardcoded defaults if config is missing.

3. File Renaming Strategy

  • Each copied file is renamed using the following format:

    <source_folder_name>_<original_filename>
    
  • Example:

    Source folder:  vacation2026
    Original file: !img01.jpg
    New filename:  vacation2026_!img01.jpg
    
  • (Optional future extension: remove ! from filename after prefixing.)


4. Dry-Run Mode

  • A --dry-run flag simulates all operations without copying any files.

  • In dry-run mode:

    • The tool prints:

      • Which files would be copied
      • Their computed destination paths
      • Their renamed filenames
    • No filesystem writes occur.

    • No log entries are written (unless explicitly enabled with a flag like --log-dry-run).


5. Logging System

5.1 Log File

  • All real (non-dry-run) operations are recorded in a log file, e.g.:

    bang_copier.log
    
  • Each log entry includes:

    • Timestamp
    • Source directory path
    • Destination directory path
    • Original filename
    • New filename
    • Operation status (SUCCESS / SKIPPED / ERROR)
    • Optional error message
  • Example log entry:

    [2026-01-25 20:42:11]
    SOURCE: /photos/vacation2026
    DEST:   /backup/photos
    FILE:   !img01.jpg -> vacation2026_!img01.jpg
    STATUS: SUCCESS
    

CLI Interface

Basic Usage

bang .

Scans the current directory and copies all !-prefixed files.


With Explicit Folder

bang /path/to/source/folder

Dry Run

bang . --dry-run

Custom Config File

bang . --config ./my_config.json

Manage Destinations

The following options allow you to inspect or mutate the list of configured destinations without performing a copy run:

bang --list-dests                 # display current destinations
bang --add-dest /path/to/dir      # append a destination
bang --remove-dest /path/to/dir   # remove a specific destination
bang --clear-dests                # delete all destinations

List destinations:

List destinations

Add destination:

Add destination

Remove destination:

Remove destination

Clear destinations:

Clear destinations

(These flags are mutually exclusive and exit immediately after performing the action.)


Configuration File (Example: config.json)

{
  "destinations": [
    "/mnt/backup/photos",
    "/mnt/cloud/photos"
  ],
  "log_file": "./bang_copier.log",
  "remove_bang_prefix": false,
  "scan_recursively": false
}

Error Handling Rules

Scenario Behavior
Source folder does not exist Exit with error message
No ! files found Print info message and exit gracefully
Destination folder missing Auto-create (optional flag-controlled)
Destination file already exists Skip + log as SKIPPED
Permission denied Log ERROR and continue with next file
Invalid config file Print error and fall back to defaults

Exit Codes

Code Meaning
0 All operations successful
1 Partial failure (some errors)
2 Fatal error (nothing executed)

Future Enhancements

Potential future additions:

  • GUI interface
  • Recursive directory scanning (--recursive)
  • File deletion after copy (--delete-after-copy)
  • File type filtering (--only-ext .jpg,.png)
  • Parallel copy
  • Remove bang prefix in output names (--remove-bang)
  • JSON log output (--json-log)
  • Stats summary output (--stats)
  • Undo last run (--undo-last-run)

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

bang_file_copier-1.0.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

bang_file_copier-1.0.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file bang_file_copier-1.0.1.tar.gz.

File metadata

  • Download URL: bang_file_copier-1.0.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for bang_file_copier-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e7bfab33521f2620985d702d13bbbed42a5fa81441327fe3a102a5622d6817da
MD5 d963d54801acc44a74bb1d53b4fd9882
BLAKE2b-256 ea6d690c570ee1abcad1c7481e281208ac737e20426f3a37f6a3331776160878

See more details on using hashes here.

File details

Details for the file bang_file_copier-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bang_file_copier-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a38dbfa315369b255b5a1d7ee9278e3a4026d8cfc977523a7e7deec6bb69eef4
MD5 9640b2b5a53a306149297cf4d7354e6f
BLAKE2b-256 1f6b86ce1c1b2f02a44aaf98db6af24897543548deb598757e9035eaa45ae3d3

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