如果你嫌用函数查找麻烦可以用控件
filelistbox
for I:=0 to filelistbox1.count-1 do
begin
filelistbox1.itmeindext:=i;
oldname:=filelistbox1.filename;
newname:=(*****)//在这里写出你想要的格式
if renamefile(oldname,newname) then
else
showmessage('重命名失败,可能有同名文件请检查!');
end;
一开始那个写错了更正一下
我在D7下面写的批量命名的一段代码(读取文本文件第一行做为他的文件名)
ProgressBar:=TProgressBar.Create(Form1);
with ProgressBar do
begin
//设定进度条的位置、宽度和高度
Top:=ProgressBarRect.Top ;
Left:=ProgressBarRect.Left;
Width:=ProgressBarRect.Right-ProgressBarRect.Left;
Height:=ProgressBarRect.Bottom-ProgressBarRect.Top;
Visible:=True; // 显示进度条
Parent:=StatusBar1;
progressbar.Position:=1;
progressbar.Max:=filelistbox1.Count;
end;
for ii:=0 to filelistbox1.Count-1 do
begin
filelistbox1.ItemIndex:=ii;
txtfile:=tstringlist.Create;
txtfile.LoadFromFile(filelistbox1.FileName);
substr:=txtfile.Strings[0];
name1:=substr+'.txt';
txtfile.Free;
if renamefile(filelistbox1.FileName,trim(name1)) then
begin
progressbar.Position:=progressbar.Position+1;
end
else
begin
showmessage('命名失败!');
progressbar.Position:=progressbar.Position+1;
end;
end;
showmessage('处理完毕!');
progressbar.Visible:=false; // not 显示进度条
progressbar.Position:=1;
end;