Renaming a file
To change a file name, simply use the RenameFile function:
function RenameFile(const OldFileName, NewFileName: string): Boolean;
which changes a file name, identified by OldFileName, to the name specified by NewFileName. If the operation succeeds, RenameFile returns True. If it cannot rename the file, for example, if a file called NewFileName already exists, it returns False. For example:
if not RenameFile(lOLDNAME.TXT','NEWNAME.TXTl) then ErrorMsg('Error renaming file!');
You cannot rename (move) a file across drives using RenameFile. You would need to first copy the file and then delete the old one.
Post a comment