|
-
December 16th, 2008, 01:22 AM
#1
Files txt counter
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
-
December 16th, 2008, 03:12 AM
#2
Re: Files txt counter
FindFirstFile() & FindNextFile() will do it.
-
December 17th, 2008, 07:15 PM
#3
Re: Files txt counter
 Originally Posted by Leite33
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.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
December 20th, 2008, 05:54 PM
#4
Re: Files txt counter
Code:
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|