05-19-2016 06:00 AM
Solved! Go to Solution.
05-19-2016 06:36 AM
05-19-2016 07:37 AM
I've not actually tried this, but the Move function has an "Overwrite" switch that will allow you to Overwrite a file if it already exists. So if I want to move OldFolder/OldFile.txt to NewFolder/NewFile.txt, all I should have to do is specify the two Paths and set Overwrite = T, and the file will be deleted from OldFolder and will appear in NewFolder as NewFile.txt, overwriting any file of that name that already exists. All in a single (logical) step.
If this doesn't work this way, please respond, and I'll be very surprised (and embarrassed).
Bob Schor
05-19-2016 07:51 AM
05-19-2016 08:42 AM - edited 05-19-2016 08:42 AM
Hi Nando,
The thing is I wish to keep both the old and the new file, that is why I want to rename the file.
Ok, just do it!
Pseudocode:
while path(oldfile) == path(newfile) append suffix to newfile filename wend
move(newfile)
05-19-2016 08:48 AM - edited 05-19-2016 08:55 AM
@Nando88 wrote:
The thing is I wish to keep both the old and the new file, that is why I want to rename the file.
OK, let's try this again. You have "OriginalFolder/OriginalFile.txt" and you want "NewFolder/RenamedFile.txt", correct? And you want OriginalFile to stay put, just have a second copy (with another, or even the same name) somewhere else. Is that right?
In that case, just use the Copy function, and if you want to overwrite a file that is in the Destination folder, set Overwrite to True.
[I may be incorrect about this, but I think Unix introduced the notion that "Move" and "Rename" were the same operation. Hence when you said "Move", I assumed it was "Copy and delete the Original"].
In either case, it is a one-step simple operation. The only time you need to do any extra processing is if you want, at run time, to be able to decide whether or not to overwrite an already-existing file in the Destination Folder.
Bob Schor
P.S. -- I just noticed GerdW's response. By "rename", did you mean what Gerd is suggesting, that is, copy but do not overwrite if a file exists? Yes, in that case, you need to do a little more work to come up with a unique file name, either for the "new" file you are bringing over, or for the existing file. When I've encountered this situation, I've added a numeric suffix (.001, .002, etc.) to the existing file, keeping them in sequence. So going back to my example, above, if I'm copying OriginalFolder/OriginalFile.txt to NewFolder/OriginalFile.txt, I would first see if the file "NewFolder/OriginalFile.txt" existed, and if so, would "Rename" (a Move function) it to "OriginalFile.nnn.txt" (where "nnn" starts with 001, and is the lowest number that is not already present in NewFolder). Once the Move/Rename is done, I can safely Copy without worrying about a "name clash".
BS
05-19-2016 09:13 AM
05-19-2016 09:19 AM - edited 05-19-2016 09:31 AM
I think I have a solution. Please correct me if I am wrong.
I would have to compare if the file exists and if it exists, I would increment a shift register, and I would have to split the filename with match pattern, and concatenate with the shift register and the file extension.
05-19-2016 11:12 AM
05-19-2016 11:15 AM