S
sam_cit
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 :
#include <stdio.h>
int main()
{
FILE *p;
p = fopen("c:\\sam.txt","r");
if(p == NULL)
{
printf("file open failed...\n");
}
else
{
printf("file open success...\n");
}
//printf("close result is %d\n",fclose(p));
printf("result of deleteion is : %d\n",remove("c:\\sam.txt"));
}
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 :
#include <stdio.h>
int main()
{
FILE *p;
p = fopen("c:\\sam.txt","r");
if(p == NULL)
{
printf("file open failed...\n");
}
else
{
printf("file open success...\n");
}
//printf("close result is %d\n",fclose(p));
printf("result of deleteion is : %d\n",remove("c:\\sam.txt"));
}