Solved

get file name without Extention

Posted on 2004-04-24
12
154 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

815 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

8 Experts available now in Live!

Get 1:1 Help Now