From: John Joyce Date: 2007-06-05T02:42:22+09:00 Subject: Re: Deleting a file - is there a less clumsy way to do this? On Jun 4, 2007, at 12:15 PM, Daniel Berger wrote: > 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 > > so check success by checking File.exists? again...? Or find out if the file is in use and then wait?