From: Ronald Fischer Date: 2007-06-04T22:14:49+09:00 Subject: Deleting a file - is there a less clumsy way to do this? In my application, I often have blocks of code, where during preparation code, I need to make sure that certain files do not exist (in practice, this might be files left over from a previous run, which I didn't want to have erased earlier). Basically, I am doing something like this: if File.exist?(filename) File.unlink(filename) end or, equivalently, begin File.unlink(filename) rescue # ignore errors - it's OK if the file does not exist end This is necessary, because File::unlink signals non-existence of the file using an exception, instead by return code (as, for example, Perl's unlink does). The resulting code looks clumsy, because one always has to take care of an exception, which does not really signal an error condition (in Perl, I would simply ignore the return code of unlink). Of course I could write my own unlink function like this: def silent_unlink(f) File.unlink(f) if File.exist?(f) end ... silent_unlink(filename) but I am wondering whether this is not a such common problem, that Ruby already might have a non-exception-throwing unlink function built in somewhere? Ronald -- Ronald Fischer Phone: +49-89-452133-162