Issue with PSUtilities.file:renameFile() after moving file to archive folder

Currently, after uploading the file to an SFTP host, I move the local file to an archive directory.

Program logic:

  1. PSUtilities.file:moveFile() — move file from
    D://upload/D://upload/backup/
  2. PSUtilities.file:renameFile() — rename the archive file from
    D://upload/backup/test_file.xlsxD://upload/backup/test_file.xlsx_20250812

Occasionally, PSUtilities.file:renameFile() fails with the following message:

PSUtilities.file:renameFile() – Move file and obtain target path

If I retry a few times, it sometimes works.

Question:

  • What could cause renameFile to fail right after moveFile?
  • Is it possible that the file is still locked by the OS after the move operation on Windows?
  • Any recommended best practices to avoid this issue (e.g., delay, direct move+rename in one step, etc.)?

Thank you!