刚好前几天做了一个批量改名的程序,把某个目录下的文件都改成一致的编号名。
参考一下吧:
procedure TForm1.RenameFiles;
var i,j: integer;
OldFileName, suffix, NewFileName: String;
begin
for i := 0 to FileListBox1.Items.Count -1 do begin
OldFileName := DirectoryListBox1.Directory + '/' + FileListBox1.Items;
j := LastDelimiter('.',OldFileName);
suffix := Copy(OldFileName,j,Length(OldFileName));
NewFileName := Edit1.Text + StringOfChar('0',4 - Length(IntToStr(i)))
+ IntToStr(i) + Suffix;
// ShowMessage(NewFileName);
if not RenameFile(OldFileName,NewFileName) then begin
ShowMessage('文件改名失败: ' + OldFileName + ' ---> ' + NewFileName);
Break
end
end;
FileListBox1.Update
end;