Skip to content

A tiny, fast Rust CLI that scans a directory tree for empty sub-directories and drops an empty `.keep` file in each one. Handy for committing directory structure to Git.

License

Notifications You must be signed in to change notification settings

joelee/keep-empty-dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

keep-empty-dir

A tiny, fast Rust CLI that scans a directory tree for empty sub-directories and drops an empty .keep file in each one. Handy for committing directory structure to Git.

Features

  • Recursively scans a path (defaults to current working directory)
  • Creates .keep in truly empty sub-directories
  • Dry run mode to preview without writing
  • Helpful summary at the end
  • Works on macOS, Linux, and Windows

Install

Using Cargo

cargo install --path .
# or if published later:
# cargo install keep-empty-dir

Build from source

git clone https://github.com/joelee/keep-empty-dir.git
cd keep-empty-dir
cargo build --release
# binary at target/release/keep-empty-dir

Usage

keep-empty-dir [PATH] [OPTIONS]
  • If PATH is omitted, the current directory (.) is used.

Options

-h, --help        Print help and usage
-v, --version     Print version (alias; also supports -V/--version)
-d, --dryrun      Only print empty directories; do not write .keep files

Examples

Scan the current directory and create .keep files:

keep-empty-dir

Scan a specific path:

keep-empty-dir ./packages/shared

Dry run (no files written):

keep-empty-dir -d ./src

Typical output:

created: /project/tmp/cache/.keep
created: /project/assets/images/.keep

Summary:
  scanned dirs: 57
  empty found:  2
  .keep created: 2
  errors:       0

How it decides a directory is “empty”

A directory is considered empty if it has zero entries (no files or sub-directories). If a directory already contains anything (including an existing .keep), it’s not treated as empty and is skipped.

Note: Symbolic links are not followed.

Exit codes

  • 0 — Completed (even if some directories were skipped)
  • 2 — Provided path does not exist or is not a directory

Read and permission errors are reported as warnings and included in the summary, but they don’t stop the scan.

Git tips

If you prefer not to commit .keep in some places, use a targeted .gitignore. If you do want to commit them, ensure your global or repo .gitignore doesn’t ignore .keep.

Example .gitignore snippet to allow .keep even when ignoring everything else:

*
!.keep

Performance

  • Uses walkdir for efficient recursive traversal.
  • Skips non-directories early.
  • Avoids following symlinks for safety and speed.

Development

Project layout

.
├─ Cargo.toml
└─ src/
   └─ main.rs

Run

cargo run -- [OPTIONS] [PATH]
# Example:
cargo run -- -d .

Lint & format

cargo fmt
cargo clippy -- -D warnings

License

MIT — see LICENSE.

Acknowledgements

Built with ❤️ in Rust, using clap for CLI ergonomics and walkdir for traversal.

About

A tiny, fast Rust CLI that scans a directory tree for empty sub-directories and drops an empty `.keep` file in each one. Handy for committing directory structure to Git.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages