Thread: seach file.exe c windows help

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Unhappy seach file.exe c windows help

    hi guys look at my code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <string.h>
    
    
    char scanforexe( HANDLE ffind, WIN32_FIND_DATA ffdata){
        int i;
        ffind=FindFirstFile("*.exe*", &ffdata);
         i=strcmp("lilo3.exe",ffdata.cFileName);
         printf ("The first file found is  %s \n", ffdata.cFileName);
           while (FindNextFile(ffind, &ffdata) != 0 && (i!=0)) {
            printf("the next files are: %s \n",ffdata.cFileName);
             i=strcmp("lilo3.exe",ffdata.cFileName);
    
    
           }
           if(i==0){printf("  file found ");}
           return 0;
                   }
    char scanfloder(HANDLE ffind ,WIN32_FIND_DATA ffdata,char *dir){
             int i,j=strlen(dir);
              strcat(dir,"*.*");
                    printf("%s\n",dir);
       printf("*********************************************************\n");
                        scanforexe( ffind, ffdata);
     printf("------------------------------------------------------------\n");
                         ffind=FindFirstFile("*.*", &ffdata);
                     printf ("The first floder found is %s \n", ffdata.cFileName);
    
    
                     while (FindNextFile(ffind, &ffdata) != 0 ) {
                    if (ffdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                   {printf("the next floder is : %s \n",ffdata.cFileName);
                      if(strcmp(ffdata.cFileName,".")!=0 && strcmp(ffdata.cFileName,"..")!=0)
                      {
                         for( i=j;i<strlen(dir);i++){
                               dir[i]='\0';
                                         }
                          printf("%s\n",dir);
                      strcat(dir,ffdata.cFileName);
    
                    SetCurrentDirectory(dir);
                      strcat(dir,"\\" ) ;
                       printf("%s\n",dir);
                   printf("%s\n",ffdata.cFileName);
                      scanfloder(ffind,ffdata,dir);
    
                        }
    
                          }
              }
    
    
                 FindClose(ffind);
                  return 0;
    
    }
    
    
    int main(){
    char *dir1="D:\\" ;
    char *dir;
    strcpy(dir,dir1);
    
    
    WIN32_FIND_DATA ffdata;
    HANDLE ffind;
    
    SetCurrentDirectory(dir);
    scanfloder(ffind,ffdata,dir);
    return 0;
      }
    the probleme is my code don't scan all the directory i don't know why plzzzzzz help
    lilo.exe is the file that i look for

  2. #2
    pwning noobs Zlatko's Avatar
    Join Date
    Jun 2009
    Location
    The Great White North
    Posts
    132
    zilot, if I understand correctly you want your program to go through your current folder and subfolders recursively. It's not doing that because you cannot reuse a handle from one folder in another. Whenever you enter scanfolder, you must first execute a FindFirstFile on that folder, and don't forget to do a FindClose when exiting scanfolder. You should not be passing the parent folder's handle to scanfolder. Rather you should be passing the full path.

    I don't think the SetCurrentDirectory has any effect on your program.

    I hope that helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:16 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM