# How to define a step to effectively delete the zig-cache directory?

**URL:** <https://ziggit.dev/t/how-to-define-a-step-to-effectively-delete-the-zig-cache-directory/4279>\
**Category:** Help\
**Tags:** build-system\
**Created:** [May 11, 2024, 4:20pm UTC](https://ziggit.dev/t/how-to-define-a-step-to-effectively-delete-the-zig-cache-directory/4279 "2024-05-11T16:20:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiac](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@aiac](https://ziggit.dev/u/aiac)\
**Post date:** [May 11, 2024, 4:20pm UTC](https://ziggit.dev/t/how-to-define-a-step-to-effectively-delete-the-zig-cache-directory/4279/1 "2024-05-11T16:20:03Z")

</div>

my clean step definition in build.zig:

```zig
        // TODO: can not delete since FileBusy error
        //
        if (b.cache_root.path) |cache_dir| {
            const delete_zig_cache_dir = b.addRemoveDirTree(cache_dir);
            clean_step.dependOn(&delete_zig_cache_dir.step);
        }

```

but it tell me FileBusy

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [May 11, 2024, 4:27pm UTC](https://ziggit.dev/t/how-to-define-a-step-to-effectively-delete-the-zig-cache-directory/4279/2 "2024-05-11T16:27:23Z")

</div>

Builder is an executable in the zig-cache.  
Deleting the zig-cache contents, includes the running builder executable.  
In Windows you cannot delete a running executable.

See also: [8) Clean `zig-out` and `zig-cache` directories](https://ziggit.dev/t/build-system-tricks/3531#h-8-clean-zig-out-and-zig-cache-directories-17)

---

<div class="post-metadata">

**Author:** ![AndrewCodeDev](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@AndrewCodeDev](https://ziggit.dev/u/AndrewCodeDev)\
**Post date:** [May 11, 2024, 5:16pm UTC](https://ziggit.dev/t/how-to-define-a-step-to-effectively-delete-the-zig-cache-directory/4279/3 "2024-05-11T17:16:27Z")

</div>

As a quick follow up, I usually define a script that I run while I am developing that clears the cache first and then runs zig build (if the project calls for that).
