[DUG] Delete (File) Function ?

John Bird johnkbird at paradise.net.nz
Mon Jun 30 15:03:54 NZST 2008


These zip files that get deleted are on a server, so it is not rebooted
often enough to fix the not-deleted files this way.  The best approach I
found was to check the return value of the DeleteFile function, and if it
was not true (successful) then retry it again next time a cleanup was due
until successful.   That seems to have worked, even though I am still in the
dark why it ever might have failed in the first place.
 
With the files left open - the application most defintely does exit and
close files properly (from its side) even if the server leaves them in use.
Some parts of it are legacy (DOS) programs but the log files always confirm
it executed its close and finish code in each case.
 
 

Not really going to get into the specifics of what's happening in your
particular instances, but another suggestion might be to make use of the
RunOnce key in the Registry to delete files the next time Windows starts up.
 
See http://delphi.about.com/cs/adptips1999/a/bltip0799_3.htm for some sample
code.
 
However, IMHO Windows itself doesn't keep files open any longer than
requested (maybe unless they're DLLs or something).  If the file in question
is a file opened/used by your application, and Windows tells you it's in
use, then I'd strongly suggest your app hasn't closed and released the file
handle properly.
 
Cheers,
 
C.

  _____  

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of John Bird
Sent: Monday, 30 June 2008 1:37 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Delete (File) Function ?


I have come across similar problems on Windows Servers over the years in a
couple of cases:
 
1 - Data Files (non-database in this case)  that have been updated and
finished with and closed may remain open or in use as far as the Server
goes.   Sometimes this times out after a few minutes and the file does
become not in use.  Sometimes it has to be closed manually on the server
(Control panel/Administrative tools/Shared files/Open Files allows one to
manually browse and close an open connection).
 
Sometimes even more puzzling is a file remaining with a locked block (a file
open for shared read/write) long after the updates have finished.  Same
solution.
 
Incidentally I discovered There is a useful Windows command line variant of
the Administrative Tools GUI - 
 
OPENFILES /Disconnect /O Read/Write (+ other options)

but  haven't yet have had a chance to find out if that only deals with files
opened from this workstation or for any workstation or whether it can be
used from a workstation to close files on the server.
 
2 - Zip file archives that get deleted after a time (usually weeks after
created) sometimes fail to delete - using the same DeleteFile call as you
used.  I have not figured out yet why these fail to delete, but they are on
a Windows server again.
 
I am most interested to hear anyone shed light on this!

John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20080630/5c327ae5/attachment-0001.html 


More information about the Delphi mailing list