• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

get file name without Extention

hello

i have a filename :='hello.java'

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

filename :=hello   only

sure for anyfile....
0
mis82
Asked:
mis82
1 Solution
 
mokuleCommented:
p := Pos('.',text);
if p > 0 then
  Delete(text,p,length(text);
0
 
shaneholmesCommented:
in the sysutils unit there is a function

uses SysUtils;


ChangeFileExt(MyFileName,'');

pass it a nil string and you get no extension


Shane
0
 
shaneholmesCommented:
In your case....

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

will return

'Hello'


Shane
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
bpanaCommented:
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
 
shaneholmesCommented:
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
 
bpanaCommented:
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
 
AlievCommented:
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
 
shaneholmesCommented:
bpana,

its a fucnction

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

in the SysUtils unit


Shane

0
 
bpanaCommented:
yep, i've seen that
that's why I posted the first comment, otherwise I wouldn't.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now