Delete a file from script using wildcards?


#1

I would like to delete, from within a script, a file with name foo-4439.bar, for example, where the number is not known, a priori. I have been trying variations on

run(`rm foo-*`)

but have not managed to come up with anything that works. There is a message about quoting special characters like “*”, but trying that does not help. TIA


#2

You need to use Julia glob rather than shell wildcards

using Glob
for f in glob("foo-*")
     rm(f)
end

or if you’re using v0.6 or later

using Glob
rm.(glob("foo-*"))

#3

Thanks, that does the trick. I had overlooked Glob.jl