Solved

get file name without Extention

Posted on 2004-04-24
12
153 Views
Last Modified: 2010-04-05
hello

i have a filename :='hello.java'

how can i get (hello) without (.java)  ?

filename :=hello   only

sure for anyfile....
0
Comment
Question by:mis82
12 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 250 total points
ID: 10908720
p := Pos('.',text);
if p > 0 then
  Delete(text,p,length(text);
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908751
in the sysutils unit there is a function

uses SysUtils;


ChangeFileExt(MyFileName,'');

pass it a nil string and you get no extension


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908760
In your case....

ChangeFileExt('Hello.java','');

will return

'Hello'


Shane
0
 
LVL 6

Expert Comment

by:bpana
ID: 10908908
Hi,

If you want the resulting filename to include the path:
FileNameWithoutExt := Copy(FileName, 1, Pos(ExtractFileExt(FileName), FileName) - 1);

If you want the filename, without the path:
FileName := ExtractFileName(FileName);
FileNameWithoutExt := Copy(FileName, 1, Pos(ExtractFileExt(FileName), FileName) - 1);

Bogdan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10909134
Actaully ChangeFileExt will do it with the path as well

procedure TForm1.Button1Click(Sender: TObject);
begin
 if OpenDialog1.Execute then
  ShowMessage(ChangeFileExt(OpenDialog1.FileName, ''));
end;


if you dont want the path, do this

ExtractFileName(ChangeFileExt(OpenDialog1.FileName, ''));

procedure TForm1.Button1Click(Sender: TObject);
begin
 if OpenDialog1.Execute then
  ShowMessage(ExtractFileName(ChangeFileExt(OpenDialog1.FileName, '')));
end;


Hope This Helps!

Shane
0
 
LVL 6

Expert Comment

by:bpana
ID: 10909265
actually my comment and Shane's are the same, but he uses less lines of code :-)

(in the first place I thought that ChangeFileExt is a procedure, not a function)

Bogdan
0
 
LVL 3

Expert Comment

by:Aliev
ID: 10909524
function getfname(file:string):string;
var
ext,ft:string;b,l:integer;
begin

ft:=extractfilename(file);
ext:=extractfileext(ft);
b:=pos(ext,ft);
delete(ft,b,length(ext));

result:=ft;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10909534
bpana,

its a fucnction

function ChangeFileExt(const FileName, Extension: string): string;

in the SysUtils unit


Shane

0
 
LVL 6

Expert Comment

by:bpana
ID: 10909613
yep, i've seen that
that's why I posted the first comment, otherwise I wouldn't.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 92
Delphi application Soap connection 5 96
Firemonkey webbrowser scrollbars ? 1 29
RESTRequest Parameter 4 14
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now