Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extracting Filemane without extension

2,227 views
Skip to first unread message

T.Gray

unread,
Sep 2, 1998, 3:00:00 AM9/2/98
to
I'm familiar with all the "extract" routines relating to files, but don't
find a standard routine to extract just the filename without the path AND
extension. I want just the filename alone (no ext). I.E. not
"Path\Filename.Ext" , just "Filename". Can anyone share a simple way to
do this?
T.Gray

Steve Schafer (TeamB)

unread,
Sep 3, 1998, 3:00:00 AM9/3/98
to
On Wed, 2 Sep 1998 20:52:25 -0500, "T.Gray" <tgray@<NOSPAM>btsg.com>
wrote:

NakedName := ChangeFileExt(ExtractFileName(FileName), '');

-Steve


Ralph Friedman (TeamB)

unread,
Sep 3, 1998, 3:00:00 AM9/3/98
to

T:

var
fileNameAlone: string;
p: integer;
tmpName: string;

begin
tmpName := ExtractFileName(somefullpath);
p := Pos('.', tmpName);

if p > 0 then
fileNameAlone := Copy(tmpName, 1, p - 1)
else
fileNameAlone := tmpName;
end;
--
Regards
Ralph (TeamB)
Herrsching, Germany
(TeamB cannot respond to questions received via email)

T.Gray btsg.com> wrote in message <6sksn3$gk...@forums.borland.com>...


|I'm familiar with all the "extract" routines relating to files, but don't
|find a standard routine to extract just the filename without the path AND
|extension. I want just the filename alone (no ext). I.E. not
|"Path\Filename.Ext" , just "Filename". Can anyone share a simple way to
|do this?

|T.Gray
|
|


Kent Briggs

unread,
Sep 3, 1998, 3:00:00 AM9/3/98
to
Ralph Friedman (TeamB) wrote:

> T:
>
> var
> fileNameAlone: string;
> p: integer;
> tmpName: string;
>
> begin
> tmpName := ExtractFileName(somefullpath);
> p := Pos('.', tmpName);
>
> if p > 0 then
> fileNameAlone := Copy(tmpName, 1, p - 1)
> else
> fileNameAlone := tmpName;
> end;

This method could fail because long file names can have multiple periods in
them. You would need to search for the last period, not the first one.

Kent

Ralph Friedman (TeamB)

unread,
Sep 3, 1998, 3:00:00 AM9/3/98
to
You are correct (old habits die hard). Change it to:

var
fileNameAlone: string;
lastDot: PChar;
p: integer;
tmpName: string;

begin
tmpName := ExtractFileName(somefullpath);

lastDot := StrRScan(PChar(tmpName), '.');
if lastDot <> nil then begin
p := lastDot - PChar(tmpName);
fileNameAlone := Copy(tmpName, 1, p)
end


else
fileNameAlone := tmpName;
end;

--
Regards
Ralph (TeamB)
Herrsching, Germany
(TeamB cannot respond to questions received via email)

Kent Briggs wrote in message <35EEB560...@briggsoft.com>...

Wolfgang Krug

unread,
Sep 4, 1998, 3:00:00 AM9/4/98
to
Why don't you use after
ExtractFileName(somefullpath);
ChangeFileExt('') ?
Wolfgang

--
Wolfgang Krug |s |d &|m | software design & management GmbH & Co. KG
| | | | Finanzinformationssysteme
kr...@sdm.de | | | | Thomas-Dehler-Str. 27, 81737 Muenchen
Telefon / Fax (089) 63812 - 489 / 150

James L. Persons

unread,
Sep 4, 1998, 3:00:00 AM9/4/98
to
On Thu, 03 Sep 1998 10:27:28 -0500, Kent Briggs <kbr...@briggsoft.com> wrote:

>
>This method could fail because long file names can have multiple periods in
>them. You would need to search for the last period, not the first one.
>
>Kent
>

Your suggestion will fail if the filename has no extension and some element of
the path does have an extension. Borland seems to have this case covered
properly in ChangeFileExt as suggested by Steve.

James L. Persons

unread,
Sep 4, 1998, 3:00:00 AM9/4/98
to
On Fri, 04 Sep 1998 13:22:27 GMT, jper...@voyager.net (James L. Persons) wrote:

>Your suggestion will fail if the filename has no extension and some element of
>the path does have an extension. Borland seems to have this case covered
>properly in ChangeFileExt as suggested by Steve.

Oops, failed to note the prior use of ExtractFileName, so there can be no path
left. Pretend you're my ex-wife and just ignore me.

Kent Briggs

unread,
Sep 5, 1998, 3:00:00 AM9/5/98
to
James L. Persons wrote:

You still had a good point, though. If you didn't use ExtractFileName, you could
search
for the last period and then make sure there were no backslashes after that. But
yes,
using changefileext with an empty string is the way to go. In my opinion, Microsoft

really made out lives unnecessarily difficult by allowing spaces (for command line
parsing) and multiple periods in long file names.

Kent

nit...@softwareassociates.co.in

unread,
Apr 9, 2016, 3:47:52 AM4/9/16
to
On Thursday, September 3, 1998 at 12:30:00 PM UTC+5:30, Steve Schafer (TeamB) wrote:
> On Wed, 2 Sep 1998 20:52:25 -0500, "T.Gray" <tgray@<NOSPAM>btsg.com>
> wrote:
>
> >I'm familiar with all the "extract" routines relating to files, but don't
> >find a standard routine to extract just the filename without the path AND
> >extension. I want just the filename alone (no ext). I.E. not
> >"Path\Filename.Ext" , just "Filename". Can anyone share a simple way to
> >do this?
>
> NakedName := ChangeFileExt(ExtractFileName(FileName), '');
>
> -Steve

thank you
0 new messages