Thread: Search more than one time

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    161

    Search more than one time

    Hi to all, I want to search all *.exe in the same folder where my program is and look for theire size. I can do it for ONE and i'm so stupid that i'm not able to use findnextfile..
    Someone can let me see how to do it ? Thanx !

    This is my code, i only need to add the findnextfile and it's finished.

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind;
     
        hFind = FindFirstFile("*.exe", &FindFileData);
    
        if (hFind == INVALID_HANDLE_VALUE) 
            printf ("No files found.\n");
        else 
        {
            printf ("I've found: %s\n", FindFileData.cFileName);
            printf ("The size is %d\n", FindFileData.nFileSizeLow);
            FindClose(hFind);
        }
        
        system("pause");
        return 0;  
    }

  2. #2
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    Here is an example:

    Code:
    WIN32_FIND_DATA fd;
    HANDLE hFind = FindFirstFile("*.exe", &fd);
    
    if (hFind != INVALID_HANDLE_VALUE) {
        do {
            // do something with fd
        } while (FindNextFile(hFind, &fd));
        FindClose(hFind);
    }

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    thanx very much for ur help but i have a problem


    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        WIN32_FIND_DATA FindFileData;
         
        HANDLE hFind = FindFirstFile("*.exe", &FindFileData);
        
        
        if (hFind != INVALID_HANDLE_VALUE) {
        do {
            printf ("I've found: %s\n", FindFileData.cFileName);
            printf ("The size is %d\n", FindFileData.nFileSizeLow);
            
        } while (FindNextFile(hFind, &FindFileData));
        FindClose(hFind);
        system("pause");
        return 0;  
    }
    dev cpp says to me :

    C:\Programmi\Dev-Cpp\Ricerca in Cartella\main.cpp
    [Warning] In function `int main()':
    27 C:\Programmi\Dev-Cpp\Ricerca in Cartella\main.cpp
    parse error at end of input
    C:\Programmi\Dev-Cpp\Ricerca in Cartella\Makefile.win
    [Build Error] [main.o] Error 1


    parse error at end of input ??? i really dont understand where is the problem !!


    EDIT : WHAT AN IDIOT I forgot the } Now it works
    Last edited by BianConiglio; 04-07-2004 at 06:00 AM.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    Now i have that problem :

    I want to search in a given path and not in the same folder where there is the program i've created..

    The code is :

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int cmd3 = 192512;
        int cmd8 = 188416;
        int graf = 413696;
        
        WIN32_FIND_DATA FindFileData;
         
        HANDLE hFind = FindFirstFile("*.exe", &FindFileData);
        
        
        if (hFind != INVALID_HANDLE_VALUE) {
        do {
            printf ("I've found: %s\n", FindFileData.cFileName);
            printf ("The size is %d\n", FindFileData.nFileSizeLow);
            
            if ((FindFileData.nFileSizeLow == cmd3)
               || (FindFileData.nFileSizeLow == cmd8)
               || (FindFileData.nFileSizeLow == graf))
                    
                 printf ("Found! %s\n\n", FindFileData.cFileName);
    
            else printf ("Not matching\n\n");
                    
        } while (FindNextFile(hFind, &FindFileData));
        FindClose(hFind);
        system("pause");
        return 0;  
    }
    
    }
    And I want to look for that *.exe files in a given path(that will change in a for cicle, but this is not a problem), what I have to do ? I will have a path in a string like "strStartPath" and i want to search here.

    Thanx

  5. #5
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    Sorry, didn't notice the thread till now, to search in a path other than your program's, FindFirstFile call should be:
    Code:
    HANDLE hFind = FindFirstFile("c:\\path\\to\\dir\\*.exe", &FindFileData);

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    yes thanx i did it days ago and it works thanx anyway ur help is allways appreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Firefox and Google Search
    By DeepFyre in forum Tech Board
    Replies: 0
    Last Post: 01-16-2005, 10:28 AM
  3. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 01:57 PM
  4. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM