Click to See Complete Forum and Search --> : Files txt counter


Leite33
December 16th, 2008, 12:22 AM
Hi i made the aove code to check if a file exist:
-----------------------------------------------------

FILE *fp;

fp=fopen("c:\\.txt","r");

if(fp==NULL)
ShowMessage("The file doesnt exist");
else
ShowMessage("File exists");
----------------------------------------------------
Can i make a simple program to check how many txt files exist on c:\\
Thank you

CatShoe
December 16th, 2008, 02:12 AM
FindFirstFile() & FindNextFile() will do it.

VladimirF
December 17th, 2008, 06:15 PM
Hi i made the aove code to check if a file exist:
-----------------------------------------------------
fp=fopen("c:\\.txt","r");
Your test is too strong: it requires you to have read access to the file, beside the fact that it exists.

r4z0rw0lf
December 20th, 2008, 04:54 PM
HANDLE hFind;
WIN32_FIND_DATA FindFileData;
hFind = FindFirstFile("C:\\*.txT", &FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
{
printf("Error: invalid path\n");
}else{
int i=1;
while(FindNextFile(hFind, &FindFileData) != 0)
{
i++;
}
printf("found %i txt files!",i);
}

should do the trick. the int i is 1 because it already found the first file.