Changes the name of an external file.UnitSystemCategoryIO routinesDelphi syntax:procedure Rename(var F; Newname: string); procedure Rename(var F; Newname: PChar);DescriptionThe external file associated with F is renamed Newname. Further operations on F operate on the external file with the new name.F is a variable of any file type. Newname is a string-type expression or an expression of type PChar if the extended syntax is enabled.Note: {$I+} handles runtime errors using exceptions. When using {$I-}, use IOResult to check for I/O errors.
uses Dialogs; var f : file; begin OpenDialog1.Title := 'Choose a file... '; if OpenDialog1.Execute then begin SaveDialog1.Title := 'Rename to...'; if SaveDialog1.Execute then begin AssignFile(f, OpenDialog1.FileName); Canvas.TextOut(5, 10, 'Renaming ' + OpenDialog1.FileName + ' to ' + SaveDialog1.FileName); Rename(f, SaveDialog1.FileName); end; end;end;
procedure Rename(var F; Newname: PChar);DescriptionThe external file associated with F is renamed Newname. Further operations on F operate on the external file with the new name.F is a variable of any file type. Newname is a string-type expression or an expression of type PChar if the extended syntax is enabled.Note: {$I+} handles runtime errors using exceptions. When using {$I-}, use IOResult to check for I/O errors.
var f : file;
begin
OpenDialog1.Title := 'Choose a file... ';
if OpenDialog1.Execute then
begin
SaveDialog1.Title := 'Rename to...';
if SaveDialog1.Execute then
begin
AssignFile(f, OpenDialog1.FileName);
Canvas.TextOut(5, 10, 'Renaming ' + OpenDialog1.FileName +
' to ' + SaveDialog1.FileName);
Rename(f, SaveDialog1.FileName);
end;
end;end;
这是精华