如何只得到文件名,而不要文件的扩展名(25分)

  • 主题发起人 tianzhegs
  • 开始时间
T

tianzhegs

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FileListBox1Change(Sender: TObject);
begin
DirectoryListBox1.Drive:=DriveComboBox1.Drive;
FileListBox1.Drive:=DriveComboBox1.Drive;
FileListBox1.Directory:=DirectoryListBox1.Directory;
DriveComboBox1.Drive:='c';
DirectoryListBox1.Directory:='c:/video';
end;

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
DriveComboBox1.Drive:='c';
end;

procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
DirectoryListBox1.Directory:='c:/video';
end;

procedure TForm1.FilterComboBox1Change(Sender: TObject);
begin
FileListBox1.Mask:=FilterComboBox1.Mask;
FileListBox1:=FilterComboBox1.FileList;
end;


通过以上几步我得到了c:/video目录下的文件,但我只想得到文件名而不要文件的扩展名,
那位朋友帮我该一该,谢谢了
 
先计算string长度,用copy减掉最后四位就行了呀
 
不一定是四位,可能2位,也可能五位,也可能没有,
用GetFileExt取得扩展名,然后得到长度,然后删除就行了。
 
去四位当然不行
如:aaa.db
岂不是错了。
从后找“.”得位置,坐处理。
 
function ExtractFileNames(FileNames:string):string;
var
S:string;
begin
S:='';
while Pos('.', FileNames) > 0 do
begin
S:=S+Copy(FileNames,1,Pos('.',FileNames)-1);
Delete(FileNames,1,Pos('.',FileNames));
end;
result:=S;
end;
 

如:
sFileName:='data.db';
sExt:=ExtractFileExt(sFileName);//即为'.db';
这样没有扩展名的文件名为:
sFile:=Copy(sFileName,1,length(sFileName)-length(sExt));
 
Ext1:=ExtractFileExt(ExtractFileName(FileName1));
这样没有扩展名的文件名为:
File1:=Copy(FileName1,1,length(FileName1)-length(Ext1));
 
给你来个简单的
var
s:string;
begin
s:=application.exename;
s:=changefileext(s,'');//将扩展名改为没有,得到没有扩展名的文件名
showmessage(s);
....
end;
 
多人接受答案了。
 
顶部