Check if the file does exist using FileExists
https://docwiki.embarcadero.com/Code...Exists_(Delphi)
if it does then
Start to cut it down in pieces, like extract the extension then you can add a number to the file name and return the extension, unless you know the type beforehand and you can check for the file and increase a number or something, there is many approaches.
the idea is to use FileExists at first then if needed you can use its clan (ExtractFilePath , ChangeFileExt, ExtractFileName, ExtractFileExt ....)