I am a bit confused about File.Copy. Initially, I was deleting a whole directory structure and then copying from a source path to a target path, but this was taking a while. Now what I am doing is only creating the directory structure on the target path if it does not already exist. If it exists, I only want to copy files if they are newer. After removing the delete, the copy goes super fast, but I am not sure if it is actually copying newer files. If I do File.Copy(source,target), does this only copy files if the do not exist? If I do File.Copy(source,target,true), does this copy the file regardless if it is newer or not?
I am a bit confused about File.Copy . Initially, I was deleting a whole
Share
File.Copy(source,target,true)will overwrite the file – regardless if it is newer or not.Copydoesn’t have logic to determine newness of files or what would be the right action.You need to implement this logic yourself – if you only want to copy newer files, you need to compare the create dates of both files and only copy newer ones.