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.e xe' = valid or if 'C:\AnyPath\test.txt' = invalid.
How can I achieve this result?
Thanks!
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.e
How can I achieve this result?
Thanks!
if UpperCase(ExtractFileExt(F ileName)) = '.EXE' then
begin
ShowMessage('Valid');
end;
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(F ileName)) = '.EXE' then
begin
ShowMessage('Valid');
end;
end;
In You Open Dialog
OD.Options := OD.Options + [ofFileMustExist];
At you testing:
if FileExists(FileName) then
begin
if UpperCase(ExtractFileExt(F
begin
ShowMessage('Valid');
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Exactly what I had in mind, thanks.
if not FileExists(FileName) then
ShowMessage('You entered a non-existing filename. Now what do you expect me to do with it ?');