Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the name part from a filename. ignoring the extension

Status
Not open for further replies.

vacunita

Programmer
Aug 2, 2001
9,166
MX
Using the ExtractFileName function i get a string that look like this: "myfile.ext" now all i want is the "myfile" part, i dont want the extension, how do i get that part only.

Any help would be apreciated. thanx
 
hi,

Their are several ways to do this but i think this is the easiest way. Use the function ChangeFileExt, with an empty string.

label1.caption := 'MyFile.Txt';
label2.caption := ChangeFileExt(Label1.caption, '');


Steph
 
Assuming your filename is in fName:
Code:
Copy(ExtractFileName(fName), 
     1, 
     Length(ExtractFileName(fName)) -
     Length(ExtractFileExt(fName))
     )
will return the string you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top