I am writing a bit of code and I need a sub that will execute a file move for me and if there is a duplicate I want to move it to a different folder and rename it.
The process will be used over and over so it is possible that a file that has previously been processed will be processed for a second time. This is what I want to trap.
Lets say that the start folder is C:\RawFiles
And the end folder is C:\ProcessedFiles
And the error folder is C:\ErrorFiles
Under normal circumstances I want to move files from C:\RawFiles to C:\ProcessedFiles but if the file name already exists in C:\ProcessedFiles then I want to move it to the C:\ ErrorFile folder
Lets say the file is TestMessage.msg
NO DUPLICATE FILES
1.Check if a file called TestMessage.msg exists in the folder C:\ProcessedFiles
If not then Move C:\RawFiles\TestMessage.ms
g to C:\ProcessedFiles\TestMess
age.msg
DUPLICATE FILES
2. If a file called TestMessage.msg exists in the folder C:\ProcessedFiles
Then make a copy of the file thats already been processed in C:\ProcessedFiles in the folder C:\ErrorFiles but rename it DF0-TestMessage.msg
i.e. the file will become C:\ErrorFiles\ DF0-TestMessage.msg DF0 = Duplicate File 0
3. If a file called C:\ErrorFiles\DF0-TestMess
age.msg already exists the folder C:\ ErrorFiles then do not make a copy of the file in the C:\ErrorFiles folder
4. Move the file C:\RawFiles\TestMessage.ms
g to C:\ErrorFiles but rename it C:\ErrorFiles\DF1-TestMess
age.msg
5. On the off chance that we already have a C:\ErrorFiles\DF1-TestMess
age.msg file in the C:\ErrorFiles folder then rename the file C:\ErrorFiles\DF2-TestMess
age.msg or C:\ErrorFiles\DF3-TestMess
age.msg and so on.
Thanks for your help