Solved

get file name without Extention

Posted on 2004-04-24
12
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

617 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