Hi to all
I've done a little program that looks for a specific file on the disk.
Once I've found that file (file_to_find.txt) I've done half work, beacuse now I want to look for an *.exe (I dont know the name beacuse it's quite allways renamed by the user, I only know 3 sizes of it that means 3 version of the same exe) that is in the same folder where I found file_to_find.txt (that the user can't rename). I want to look for that *.exe and I want know it's NAME.EXTENSION (or only the name.....I know it's an exe)
The code for the search in C is this one :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//Looking for a File by BianConiglio //
int look4aFile (char* strStartPath)
{
HANDLE hFileSearch;
WIN32_FIND_DATA hFileSearchData;
int lastError = 0;
char* currentSearchPattern = (char*) malloc( MAX_PATH );
char* reservedBuffer;
if (currentSearchPattern)
{
if (!strStartPath)
strStartPath = "C:\\";
strcpy (currentSearchPattern, strStartPath);
strcat (currentSearchPattern, "*");
if ( (hFileSearch = FindFirstFile(currentSearchPattern, &hFileSearchData)) != INVALID_HANDLE_VALUE )
{
do {
if ( strcmp(hFileSearchData.cFileName, ".") && strcmp(hFileSearchData.cFileName, "..") )
{
if ( hFileSearchData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
reservedBuffer = (char*) malloc( MAX_PATH+1 );
if ( reservedBuffer )
{
strcpy (reservedBuffer, strStartPath);
strcat (reservedBuffer, hFileSearchData.cFileName);
strcat (reservedBuffer, "\\");
lastError = look4aFile (reservedBuffer);
free (reservedBuffer);
} else
lastError = -1;
} else {
if ( !stricmp(hFileSearchData.cFileName, "file_to_find.txt" ))
printf ("I've found a file \"%s\" in the folder \"%s\"\n", hFileSearchData.cFileName, strStartPath);
}
}
}
while ( FindNextFile(hFileSearch, &hFileSearchData) );
} else
lastError = 1;
free (currentSearchPattern);
FindClose (hFileSearch);
} else
lastError = -1;
return lastError;
}
int main()
{
look4aFile (NULL);
system("PAUSE");
return 0;
}
In that "for" I have to add the code for searching the exe (the exe size is standard, i have 3 sizes that i can define in the program)
Code:
if ( !stricmp(hFileSearchData.cFileName, "file_to_find.txt" ))
printf ("I've found a file \"%s\" in the folder \"%s\"\n", hFileSearchData.cFileName, strStartPath);
strStartPath is the path found, I have to search in it an exe with one fo the 3 (defined) size... some help ?
Thanx to everyone