fileExists() is a FileSystemObject method, not a global scope function.
You also have a delete problem, DeleteFile() also a FileSystemObject method.
Also, it seems you are moving the file and then trying to solve the rewriting problem, which is out of order. You must first define a name collision so that you can first transfer the file or delete the collision. I assume that for some reason you want to keep deleting new files until you get to the last one, which was apparently implied in your question.
So you can use the block:
if NOT fso.FileExists(newname) Then file.move fso.buildpath(OUT_PATH, newname) else fso.DeleteFile newname file.move fso.buildpath(OUT_PATH, newname) end if
Also note that string comparison with the = sign is case sensitive. Use strCmp with the strCmp option to compare vbText strings.
source share