Copy only new files

I am attempting to copying only new files from source directory to destination directory.

I started with FilesystemObject.filecopy with overwrite set to False.

fso = CreateObject("Scripting.FileSystemObject");
 	fso.CopyFile( "C:\\Source\\", "C:\\Destination\\",False ); // copy
 	

However this failed because some already existed and gives a fail.

So I switched to xcopy and created a .bat that I ran from Amibroker batch execute and wait.

xcopy "C:\Source\" "C:\Destination\" /d /s /y

However this will to not work if file is open, so I created another .bat file with Robocopy and ran the .bat file with Amibroker Batch execute and wait.

robocopy "C:\Source" "D:\Destination" /XO /XC

and this seems to work, but my question is, might there be a better way to do this?

I am not exactly sure what is your intention of copying only new file.
I assume all files in Source folder as backup and the latest files in Destination folder for processing.

  1. Use this read the file name in a folder and the date is embedded in the filename. You can extract those with the latest date.
    AFL Function Reference - FDIR (amibroker.com)
  2. During the creation of each files in Source folder, duplicate a copy of standard name in Destination folder. In this case, Destination folder will always have the latest files as the old ones get replaced during each file creation cycle.

Thanks for your response, how do you suggest I extract those with latest date?

I guess I could use FDIR for source and destination and compare them to one another and know if I should copy the file.

This is just an example.
20240909_abc.txt
20240910_abc.txt
You can AFL string function to determine which file is the latest.
FDIR returns a comma separated string.
Use Strextract and check each date in the file name.
AFL Function Reference - STREXTRACT (amibroker.com)

ok thanks, they are not currently named this way, but that is a possibility, thanks, but I think the robocopy will work, just know there are a lot smarter minds out here than mine so I wanted to see what suggestions there were.

@TibetanTreeFrog, I suggest to take a look at the documentation of:

fgetstatus()

This function retrieves file properties/status including the file date/time (created/modified/last accessed).