Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7124

Re: How to delete a file that has a process running on it...

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 2015-07-21 20:53 +0000
Organization Aioe.org NNTP Server
Message-ID <20150721133527.141@kylheku.com> (permalink)
References <b45d3246-e870-4fc0-b510-90a335d729fe@googlegroups.com>

Show all headers | 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 | NextPrevious in thread | Find similar


Thread

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