Re: remove() [ to delete a file ] fails



sam_cit@xxxxxxxxxxx wrote:

Hi Everyone,

I'm using remove() function to delete a file, and i observed the
following behavior,

Concerned file : sample.txt
Operation : i open the file in read mode and don't close the file.
remove() returns -1 and the file is not deleted.

The above operation is successful when i close the file just before
the delete. Does having a file handle to a file impact remove() ? Is
this documented somewhere?

Code sample :
[...]
p = fopen("c:\\sam.txt","r");
[...]
printf("result of deleteion is : %d\n",remove("c:\\sam.txt"));
[...]

What happens when you use remove() on an open file is implementation-
defined.

Windows will not let you delete a file that is open.

<OT>
Note that you may be able to use the Windows-specific GetLastError()
to determine _why_ remove() failed. Check your manual or ask in a
Windows-specific group on how to use GetLastError() and how to
translate the number into an error message. I would suspect that
your program would give you some sort of "file in use" error.
</OT>

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@xxxxxxxxx>

.



Relevant Pages

  • Pls help! still missing msdxm.ocx
    ... I have followed your suggestion, ... using Windows 98 2nd edition: ... it pops up an error message: ... GetLastError returns 0x00000485 ...
    (microsoft.public.windowsmedia.player)
  • HELP ERROR
    ... 940 printer error code 50c help ... certificate errors internet explorer help ... computer help error message on startup ... help for microsoft windows errors ...
    (sci.geo.fluids)
  • Re: << SBS news for the week of February 1, 2004>>
    ... > 829358 Overview of the Critical Update for SQL Server 2000 Desktop Engine ... > 831747 Overview of the Business Contact Manager for Outlook 2003 Update: ... > 829114 How to remove and how to install the Windows Small Business Server ... > 831664 "The requested media failed to mount" error message when you try to ...
    (microsoft.public.backoffice.smallbiz)
  • Re: w2k sp4 and sqlsp3a - server continually restarts
    ... Windows 2000" ... 0x00000050' Error Message" ... Messages Occur When You Attempt to Synchronize Exchange Server Mail" ... message or your computer unexpectedly restarts" ...
    (microsoft.public.win2000.general)
  • Re: Why do I frequently get BSODs if I log in too fast?
    ... You May Receive a "Stop 0x1E" Error Message Intermittently in Windows 2000 ... Sfmsrv.sys on a Windows 2000-based server when more than half of the server's users have disconnected. ... frequently got a BSOD within a few seconds of logging in. ...
    (microsoft.public.win2000.general)