First of all hi everyone,
my problem is, that my program creates a file, which is read by another program and after hat my program should delete the file.
I use the following code below to check if the file exists and if any other program uses the file. After the that I want to delete the file with:
if(isFileRdy("C:\\test\\foo.txt"))remove("C:\\test\\foo.txt");
Does anyone have any idea, where the problem could be.
Interestingly this works for other files. And the foo.txt
is also created by this program without special access rights.
Thanks :)
/* just suppose the things with argc and argv work, I know it's uggly
but I need it as a call back function later in the code */
BOOL isFileRdy(char *filePath)
{
int argc = 1;
void *argv[1];
argv[0]= (void*) filePath;
return isFileRdyCBF(argv, argc);
}
BOOL isFileRdyCBF(void *argv[], int argc)
{
/* I used */
char *filePath = (char*) argv[0];
FILE *fDes = NULL;
BOOL _fileExists = FALSE;
BOOL _fileBussy = TRUE;
_fileExists = fileExists(filePath);
if(_fileExists)
{
fDes = fopen(filePath, "a+");
if(fDes!=NULL)
{
_fileBussy = FALSE;
if(fclose(fDes)!=0)
{
printf("\nERROR could not close file stream!");
printf("\n '%s'\n\n", filePath);
return FALSE;
}
}
}
return (_fileExists==TRUE && _fileBussy==FALSE) ? TRUE : FALSE;
}