Re: remove() [ to delete a file ] fails
- From: Kenneth Brody <kenbrody@xxxxxxxxxxx>
- Date: Tue, 07 Nov 2006 12:17:51 -0500
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>
.
- References:
- remove() [ to delete a file ] fails
- From: sam_cit
- remove() [ to delete a file ] fails
- Prev by Date: Re: different struct sizes
- Next by Date: #pragma cancel_handler
- Previous by thread: Re: remove() [ to delete a file ] fails
- Next by thread: Getting Integer from String?
- Index(es):
Relevant Pages
|