I am looking for a script that I can incorporate into an existing script which would allow me to do the following:
Folder1 - contains new text files that are written to it daily
Folder2 - copies of newest file that arrived in Incoming1 otherwise keep folder blank
When I run the script, I want it to look inside Folder1 and detect the newest most recent text file which has been written inside this folder. Copy that file to a folder called Folder2. When I run the script again, if it detects that the newest file in in Folder1 is the same as the file in Folder2, then delete the file in Folder2. When I run the script yet again, if it notices that the file in Folder1 is still the newest file and has not changed since the last time it was copied into Folder2, and if Folder2 is empty, then do not copy the file in Folder2. Keep Folder2 empty until when I run the script yet again, if it finds that there is a newer file in Folder 1 then copy it into Folder 2... and so forth.
Folder2 should only once contain the newest file found in Folder1, otherwise it should be kept empty, until there is a newer file in Folder1.