What is the equivalent of Ruby FileUtil.rm_f?

btw: rm -f is useful in some case, e.g. we want delete all files but no folder, no prompt.


Refer to FileUtils rm methods


I see, the Ruby FileUtils.rm_f equivalent is File.delete?, there is no equivalent in FileUtil.

I will create a issue to discuss add it.

Don’t think so, File.delete is only for single file, while Ruby File.rm can take a file or list of files. So equivalent would be FileUtils.rm method, which have overloaded methods.

PS: I don’t have any Ruby knowledge, and i’m making my judgement by looking at the doc link you provided.

It’s the same in Crystal, unless I’m missing something:


1 Like

You are right, we are missing two methods:

def rm_f(path : Path | String) : Nil # this one is a alias of File.delete
def rm_f(paths : Enumerable(Path | String)) : Nil # this one is missing

#rm_rf same as command line: rm -rf
#rm_f same as command line rm -f

       -f, --force
              ignore nonexistent files and arguments, never prompt

       -r, -R, --recursive
              remove directories and their contents recursively

rm -rf is too dangerous for almost all cases.

created issue Add FileUtils.rm_f for delete all files but no folder, no prompt. · Issue #12715 · crystal-lang/crystal · GitHub