Solved

get file name without Extention

Posted on 2004-04-24
12
152 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

21 Experts available now in Live!

Get 1:1 Help Now