dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Files txt counter

  1. #1
    Join Date
    Jul 2006
    Posts
    285

    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

  2. #2
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    Re: Files txt counter

    FindFirstFile() & FindNextFile() will do it.

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Files txt counter

    Quote Originally Posted by Leite33 View Post
    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...

  4. #4
    Join Date
    Dec 2008
    Posts
    11

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)