From: Luis Lavena Date: 2008-07-10T19:41:01+09:00 Subject: Re: How to delete a file in Win XP On Jul 10, 12:11 pm, MAwiniarski wrote: > On Jul 10, 9:39 am, Luis Lavena wrote:> On Jul 10, 7:51 am, MAwiniarski wrote: > > > > using: system('del ' + filename) > > > > output is: .The process cannot access the file because it is being > > > used by another process. > > > > How to unlink file from all processes ?? > > > Short answer: you can. > > > Windows don't let you remove files that remain open or captured by > > other process. There is also no easy way to access the unlocking API > > to release those file handlers. > > I'm trying to delete normal file which I CAN delete with windows > explorer. > And file is not opened by another application. It is simple 0 bytes > file > created earlier as a mock file for application development testing. > Ok, you're trying to delete the file from the same process? If the file was created with this syntax: f = File.open('foo', 'w') then you need to close it (f.close) sometimes that doesn't work, so better if you do the file operations in a block: File.open('foo', 'w') do |f| f.puts "xxx" end That will release the file description and let you unlink it. If, by contrary, you fold the file descriptor, nothing can be done (use Unlocker to see who is holding the file). HTH, -- Luis Lavena