Write an application that can browse directories, run any EXE file and forcibly close it after the time specified by the user. I can't find files with exe extension

String S; //Структура описывает файл WIN32_FIND_DATA FindFileData; //дескриптор потока HANDLE hf=FindFirstFile((Form5->Edit2->Text).c_str(), &FindFileData);//путь указываем где искать INT i=0; if (hf==INVALID_HANDLE_VALUE) { ShowMessage("Папка не найдена"); return 1; } do { if (strstr((char*)FindFileData.cFileName,".exe") != NULL)//не работает условие..файлы есть но не находит { S=Form5->ListBox1->Items->Strings[Form5->ListBox1->ItemIndex]; ShowMessage("Нашел"); } } while (FindNextFile(hf, &FindFileData)); FindClose(hf); 

The condition if (strstr((char*)FindFileData.cFileName,".exe") != NULL) does not work, although there are files.

  • one
    What is the question? (And why do you use WinAPI, and not the standard library?) - VladD
  • It is necessary through winapi ... the condition does not work where strstr () is - Vasily Trofov
  • help correct the mistake - Vasily Trofov
  • What is written in (Form5-> Edit2-> Text) .c_str (),? - Unick
  • (1) Why is it necessary? (2) Well, and write in the question. And specify what kind of error. - VladD 4:19

1 answer 1

As follows from the discussion in the comments, the path to the directory is passed to the FindFirstFile function. But according to the documentation there should be a path and a file mask. If all files are needed, call this function like this:

 FindFirstFile((Form5->Edit2->Text + "\\*.*").c_str(), &FindFileData); 

If you want to select only exe-files, then:

 FindFirstFile((Form5->Edit2->Text + "\\*.exe").c_str(), &FindFileData); 

In the latter case, the extension check is not needed - the files found will already have the required extension.