Determining the file name opened in OpenDialog without an extension
  • Completed the answer. - DelphiM0ZG

2 answers 2

FilenameWithoutExt:=ChangeFileExt(ExtractFileName(OpenDialog1.Filename),''); 

    I do not quite understand what you need, if you want to get the file name, then OpenDialog has the FileName property, which contains the full file name. And in order to open any files (including those without an extension), write the star property of the OpenDialog component in the Filter property of the OpenDialog component or leave it empty. If, you just need the name of the file without the path to it, then for this there is a function ExtractFileName, but I don’t know the functions for removing the extension. A similar question is seen here 1 . Or, alternatively, you can use string functions: Copy (<String>, <Number of the character from which to start copying>, <How many characters to copy>) and Pos (<Substring>, <String>).

    I wrote this code:

     procedure TForm1.btn1Click(Sender: TObject); Var FName: String; begin If Not(dlgOpen1.Execute) Then Exit; FName:=ExtractFileName(dlgOpen1.FileName); If (Pos('.', FName)<>0) Then FName:=Copy(FName, 1, Pos('.', FName)-1); btn1.Caption:=FName; end; 

    Instead of the Pos function, you can use AnsiPos.

    • @ DelpiM0ZG I need after to get the name of the open file in OpenDialog without an extension. Are there any built-in functions for this? - ivan89