# Removing directory contents recursively

**URL:** <https://discourse.julialang.org/t/removing-directory-contents-recursively/128761>\
**Category:** General Usage\
**Tags:** shell, filesystem\
**Created:** [May 6, 2025, 2:45pm UTC](https://discourse.julialang.org/t/removing-directory-contents-recursively/128761 "2025-05-06T14:45:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 6, 2025, 3:03pm UTC](https://discourse.julialang.org/t/removing-directory-contents-recursively/128761/2 "2025-05-06T15:03:34Z")

</div>

> [@floswald](#):
>
> how to do this quoting properly?

It has nothing to do with quoting. As explained in the old thread you just resurrected, wildcards like `*` are a feature of a shell, not a feature of `rm`, so you need to execute a shell, e.g.

```julia
run(`sh -c "rm -rf $(ReproData.root())/code/*"`)

```

Of course, this is not portable because not all systems have `sh` or `rm`. You could also do it in Julia, something like:

```julia
foreach(readdir(joinpath(ReproData.root()), "code"), join=true)) do filename
    rm(filename, recursive=true, force=true)
end

```

or using the Glob.jl package for more flexibility.

PS. Note that using shell globbing like `*` has been discussed extensively. See also [Is there any way to run an external command with \* in it?](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926) and [How to use \* with backticks](https://discourse.julialang.org/t/how-to-use-with-backticks/11682) and [Delete a file from script using wildcards?](https://discourse.julialang.org/t/delete-a-file-from-script-using-wildcards/7022) and [Executing system commands "backtick-like" way in Julia?](https://discourse.julialang.org/t/executing-system-commands-backtick-like-way-in-julia/114890) … if an old thread does not clarify things for you, please **do not comment on an old thread with new questions**. Create a _new_ thread, explain your question, and feel free to link other threads that might be relevant.

---

_[View the full topic](https://discourse.julialang.org/t/removing-directory-contents-recursively/128761)._
