Skip to content

Add recursive directory deletion#147

Draft
rovolsw wants to merge 9 commits intotsoding:mainfrom
rovolsw:feat/delete-recursively
Draft

Add recursive directory deletion#147
rovolsw wants to merge 9 commits intotsoding:mainfrom
rovolsw:feat/delete-recursively

Conversation

@rovolsw
Copy link

@rovolsw rovolsw commented Oct 6, 2025

Related PRs:

Related commit:

This PR features a recursive directory deletion to nob.h based on the incremental directory iterator in #145, which is built upon DFS.

New functions:

  • [API] nob_delete_directory(): deletes empty directories
  • [API] nob_delete_directory_recursively(): deletes directories recursively
  • [INNER] nob__delete_directory_recursively(): implementation of nob_delete_directory_recursively()

Example:

nob_delete_directory_recursively("./build");
nob_delete_directory_recursively("./bin");
nob_delete_directory_recursively("./obj");
// etc.

Functions:
- `nob_is_dir_empty()`
- `nob_dir_iter_open()`
- `nob_dir_iter_next()`
- `nob_dir_iter_close()`
- `nob_dir_iter_getname()`
New APIs in `nob.h`:
- `nob_delete_directory()`: deletes empty directory
- `nob_delete_directory_recursively()`: deletes directory recursively
One internal function:
- `nob__delete_directory_recursively()`
Change allocation method from dynamic allocation (malloc) to
stack allocation.
From `nob_da_free(path_sb)` to `nob_sb_free(path_sb)`.
@rovolsw rovolsw mentioned this pull request Oct 7, 2025
@Qfresquin
Copy link

This is very useful. I recently ran into the exact need for nob_delete_directory_recursively() while building a test runner on top of nob.

My project generates temporary build artifacts per test suite (probes, try_compile executables, coverage data, etc.) and I needed a clean sandbox mechanism. Without recursive deletion, this required custom platform-specific cleanup logic outside of nob.

The incremental iterator from #145 + DFS-based recursive deletion here is exactly the right architectural direction compared to the earlier nob_read_entire_dir() approach.

Looking forward to this being merged after #145.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants