From: Daniel Berger Date: 2007-06-05T02:15:04+09:00 Subject: Re: Deleting a file - is there a less clumsy way to do this? On Jun 4, 9:26 am, "Ronald Fischer" wrote: > > > Basically, I am doing something like this: > > > > if File.exist?(filename) > > > File.unlink(filename) > > > end > > > You can get it down to one line by doing this: > > > File.delete(filename) if File.exist?(filename) > > > That doesn't look so bad. :-) > > Well, I'm not so much concerned about the *lines* of code, > but of the complexity, in particular since this variation > requires to name "filename" twice. > > (side note: why does this remind me to the ongoing thread > "Introducing the "it" keyword"..... ;-) > > In Perl for instance, I would simply write > > unlink filename; > > and implicitly void the result... > > Ronald Note that this approach would silently fail on MS Windows if another process had an open handle on the file in question, i.e. the file _does_ exist, but you did not delete it. Regards, Dan