Discussion:
Remove extension from file name?
(too old to reply)
WiLLBERT
2004-07-05 07:04:46 UTC
Permalink
Any easy way to do this?

To give you an example, say I want the filename of a .txt file without the
extension, like this, only in working code:

var
x: string;
begin
x := ExtractFileName(Edit1.Text - '.txt');
end;

Cheers,
Will
--
[Firefox - Take back the web]
http://www.getfirefox.com
Maarten Wiltink
2004-07-05 08:01:10 UTC
Permalink
Post by WiLLBERT
Any easy way to do this?
Yes. So easy that I can't take credit for it; I got the idea from
some code at work. It's not my style to do things this simply.
Post by WiLLBERT
To give you an example, say I want the filename of a .txt file without
var
x: string;
begin
x := ExtractFileName(Edit1.Text - '.txt');
end;
L1 = Length(Filename) - there's a call to get that
L2 = Length(Extension) - there _is_ a call to get that
BareFilename = Copy(Filename, 1, L1-L2)
- there's no direct call to get that

Groetjes,
Maarten Wiltink
Jeremy Collins
2004-07-05 09:06:11 UTC
Permalink
Post by WiLLBERT
Any easy way to do this?
To give you an example, say I want the filename of a .txt file without the
Look at the ChangeFileExt function.
--
jc

Remove the -not from email
AlanGLLoyd
2004-07-05 08:15:24 UTC
Permalink
Post by WiLLBERT
To give you an example, say I want the filename of a .txt file without the
FileNameNoExt := ChangeFileExt(ExtractFileName('E:\MyStuff\MyFile.txt'), '');

Alan Lloyd
***@aol.com
WiLLBERT
2004-07-05 18:16:56 UTC
Permalink
Post by AlanGLLoyd
Post by WiLLBERT
To give you an example, say I want the filename of a .txt file without the
FileNameNoExt := ChangeFileExt(ExtractFileName('E:\MyStuff\MyFile.txt'), '');
Thanks. Believe it or not, that's exactly how I ended up doing it. Thank god
for about.com and this group.

-WiLLBERT
--
[Firefox - Take back the web]
http://www.getfirefox.com
Loading...