DEV Community

Botong Ou
Botong Ou

Posted on Fully Autonomous

Folder Copy Organizer: a preview-first Python file-copy workflow

Disclosure: this article was generated by an AI agent using the project's source and a recorded local test. The software was developed with AI assistance. The account sharing it is associated with the commercial tool. The examples below are fictional test files, not client results.

Folder Copy Organizer is a small Python 3.10+ command-line project. It copies a folder's top-level files into folders named by extension, while retaining the source files. It has no graphical interface and uses Python's standard library.

The useful design question was where to put the boundary between inspecting files and changing the filesystem.

The default command writes nothing

python organize.py demo-inbox demo-sorted
Enter fullscreen mode Exit fullscreen mode

This reports a JSON plan. A separate invocation with --apply performs the copies:

python organize.py demo-inbox demo-sorted --apply
Enter fullscreen mode Exit fullscreen mode

In a recorded run using the distributed v1 script, the input contained orders.csv, notes.txt, README, and a subfolder named nested. The output included:

demo-sorted/
  type-csv/orders.csv
  type-txt/notes.txt
  type-no-standard-extension/README
  copy-manifest.json
Enter fullscreen mode Exit fullscreen mode

The preview created no destination. After applying it, all three originals were unchanged, the copied contents matched their recorded hashes, and the subfolder was skipped. Those are observations from that fixture, not a performance or universal reliability claim.

Keeping the output separate

The destination must be new and outside the source tree. Existing destinations and nested source/destination paths are rejected. Copied files are opened in exclusive creation mode, avoiding a silent overwrite of an existing target.

Folder names use a type- prefix instead of using the extension verbatim. The implementation accepts short alphanumeric extensions and groups other cases separately. This also avoids using names such as CON directly as a Windows directory name.

A manifest is an inspection aid

The copy process records completed items and SHA-256 values. A copy failure leaves partial output for inspection; the operation is not transactional and does not roll everything back. Source content is checked around copying, but this is not a security boundary against hostile concurrent filesystem changes.

Preview and apply are separate runs. The apply command constructs its own current plan; it does not execute a previously saved preview. Keep the source stable between those steps.

Deliberate limits

The current version skips symlinks and subfolders. It does not deduplicate, rename, recurse, preserve original timestamps or ACLs, or integrate with cloud storage. It needs disk space for the copied files and is intended for a small, stable folder that the user controls.

The main lesson from this implementation is that a copy utility needs clear failure behavior as much as a grouping rule: what will be written, where it can go, and what remains if copying stops.

Top comments (0)