首先大家好,
我的问题是,我的程序创建了一个文件,该文件由另一个程序读取,之后我的程序应该删除该文件。
我使用下面的代码来检查文件是否存在以及是否有其他程序使用该文件。之后我想删除文件:
if(isFileRdy("C:\\test\\foo.txt"))remove("C:\\test\\foo.txt");
有谁知道问题可能出在哪里。有趣的是,这适用于其他文件。并且foo.txt
也是由这个程序创建的,没有特殊的访问权限。
谢谢 :)
/* 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;
}