[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

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!
0
John86a
Asked:
John86a
  • 3
1 Solution
 
Geert GruwezOracle dbaCommented:
use

if not FileExists(FileName) then
  ShowMessage('You entered a non-existing filename.  Now what do you expect me to do with it ?');
0
 
fromerCommented:
if UpperCase(ExtractFileExt(FileName)) = '.EXE' then
begin
  ShowMessage('Valid');
end;
0
 
fromerCommented:
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;

0
 
fromerCommented:
remember that you have to change the FileName with Your EditBox's text like,

if FileExists(Edit1.Text) then
begin
  if UpperCase(ExtractFileExt(Edit1.Text)) = '.EXE' then  
  begin
    ShowMessage('Valid');
  end;  
end;
0
 
John86aAuthor Commented:
Exactly what I had in mind, thanks.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now