NakedName := ChangeFileExt(ExtractFileName(FileName), '');
-Steve
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
|
|
> 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
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 |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
>
>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.
>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.
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