Link to home
Start Free TrialLog in
Avatar of John86a
John86a

asked on

Delphi 7 - How to detect whether an executable file was selected with dialogbrowser?

On a form I have one edit, one open dialog, two buttons, one to browse with the open dialog and the other to test the result.

Upon selecting a file, I need to verify if the Edit contains a valid path to an application, i.e.: 'C:\Path\Can\Be\Any\test.exe' = valid or if 'C:\AnyPath\test.txt' = invalid.

How can I achieve this result?

Thanks!
Avatar of Geert G
Geert G
Flag of Belgium image

use

if not FileExists(FileName) then
  ShowMessage('You entered a non-existing filename.  Now what do you expect me to do with it ?');
Avatar of fromer
fromer

if UpperCase(ExtractFileExt(FileName)) = '.EXE' then
begin
  ShowMessage('Valid');
end;
A paranoiac version...
In You Open Dialog
OD.Options := OD.Options + [ofFileMustExist];

At you testing:

if FileExists(FileName) then
begin
  if UpperCase(ExtractFileExt(FileName)) = '.EXE' then  
  begin
    ShowMessage('Valid');
  end;  
end;

ASKER CERTIFIED SOLUTION
Avatar of fromer
fromer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John86a

ASKER

Exactly what I had in mind, thanks.