Removing directory contents recursively

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.

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:

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? and How to use * with backticks and Delete a file from script using wildcards? and Executing system commands "backtick-like" way in Julia? … 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.

3 Likes