Ok now it works but I'm not able to do the next step.
I want to create a file in the same directory where it is found the default file (prova.txt)
here it is the Look4aFile i've added commens with "// <---" in capital letters where I added code from the last post. ( only some lines and i'm allready stopped by errors )
Code:
int look4aFile (char* strStartPath)
{
HANDLE hFileSearch;
WIN32_FIND_DATA hFileSearchData;
FILE *userinfo; // <-- THE FILE I WANT TO CREATE
char temp[100]="\0"; // <-- A STRING WITH THE FULL PATH
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, "prova.txt" ))
printf ("Ho trovato un file \"%s\" nella cartella \"%s\"\n", hFileSearchData.cFileName, strStartPath);
strcpy (temp,strStartPath); // <-- I COPY THE PATH FOUND
strcat (temp,"\\user_info.sah"); // <-- I ADD TO THE PATH THE NAME OF THE FILE I WANT TO CREATE
userinfo = fopen(temp, "wb"); // <-- I CREATE THE EMPTY FILE
fclose(userinfo); // <-- CLOSED
}
}
}
while ( FindNextFile(hFileSearch, &hFileSearchData) );
} else
lastError = 1;
free (currentSearchPattern);
FindClose (hFileSearch);
} else
lastError = -1;
return lastError;
}
IT doesnt work and i need help for 2 things :
1st It crushes i think i did something wrong with the string..maybe..
2nd I have to clean the "temp" string because it is a "do--while" and i can find more than one "prova.txt" and i want to create more than one "user_info.sah" so the temp string has to be celan for the next time
Thank u everyone for an hand