See steps below how to reproduce. I use Delphi 10.1 Berlin and Windows 10 and compile to win32.
- Create a new VCL Forms Application
- Place a TTimer and a TMemo on the form
- Set the timer's Interval to 10 ms
- Put this code in the OnTimer event:
if FileExists('named.txt') then
begin
Memo1.Lines.Add('named.txt exists');
DeleteFile('renamed.txt'); //delete if it exists
if RenameFile('named.txt', 'renamed.txt') then
Memo1.Lines.Add(' renamed OK')
else
Memo1.Lines.Add(' rename failed with error : '+ IntToStr(GetLastError));
end;
Run the program
Create a file named.txt
TMemo output shows:
named.txt exists renamed OK
- Now rename the file renamed.txt back to named.txt in the explorer.
TMemo output now shows:
named.txt exists renamed OK named.txt exists renamed OK
But there will come an error message showing "File or folder does not exists". Why?
(Renamefile returns OK).
Setting the timer's Interval to e.g 500 ms seems to be ok (no error message).
Here is the message (in Swedish):
I even copied the exe-file to another PC with the same result: