Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #7124
| Path | csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Kaz Kylheku <kaz@kylheku.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Re: How to delete a file that has a process running on it... |
| Date | Tue, 21 Jul 2015 20:53:51 +0000 (UTC) |
| Organization | Aioe.org NNTP Server |
| Lines | 24 |
| Message-ID | <20150721133527.141@kylheku.com> (permalink) |
| References | <b45d3246-e870-4fc0-b510-90a335d729fe@googlegroups.com> |
| NNTP-Posting-Host | OGJi3KNpFOhM58UHZwXj0w.user.speranza.aioe.org |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | slrn/pre1.0.0-18 (Linux) |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.ruby:7124 |
Show key headers only | View raw
On 2015-07-21, trekr5 <cebirim@gmail.com> wrote: > Hello, > > I've got a situation where I want to delete a file, using Ruby, on a windows > machine that is locked by another process. > > I have tried a ruby block of opening and closing a file, unlocking the file > using file.flock and then trying a FileUtils.rm(file). > > However I've tried all of these methods and the file won't delete. > > I've put exception handling around mo code and it returns a permission error when attempting to delete the file. On Windows, you cannot move or delete a file which is in use. (Not "locked", but simply open by a process.) This is a stupid Windows design problem, and Windows provides a stupid non-solution for it in the form of a retarded API. You have to use the Win32 API function MoveFileEx. MoveFileEx can be used to move files not only immediately, but after a reboot (using the MOVEFILE_DELAY_UNTIL_REBOOT flag). If you use this flag, and specify a null pointer for the destintion name, then the file will be scheduled for deletion at the next reboot.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar
How to delete a file that has a process running on it... trekr5 <cebirim@gmail.com> - 2015-07-21 10:03 -0700 Re: How to delete a file that has a process running on it... Kaz Kylheku <kaz@kylheku.com> - 2015-07-21 20:53 +0000
csiph-web