
' Use the Path.Combine method to safely append the file name to the path. Catch exception if the file was already copied.Ĭatch (DirectoryNotFoundException dirNotFound)ĭim backupDir As String = "c:\archives\2008"ĭim picList As String() = Directory.GetFiles(sourceDir, "*.jpg")ĭim txtList As String() = Directory.GetFiles(sourceDir, "*.txt")ĭim fName As String = f.Substring(sourceDir.Length + 1) Will not overwrite if the destination file already exists.įile.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName)) Will overwrite if the destination file already exists.įile.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true) Use the Path.Combine method to safely append the file name to the path. String fName = f.Substring(sourceDir.Length + 1) String txtList = Directory.GetFiles(sourceDir, "*.txt") String sourceDir = backupDir = picList = Directory.GetFiles(sourceDir, "*.jpg")
#Prodiscover basic copy image file code
The code demonstrates that this overload does allow overwriting files that were already copied. It then uses the File.Copy(String, String, Boolean) method overload to copy pictures (.jpg files). The code demonstrates that this overload does not allow overwriting files that were already copied.

It first uses the File.Copy(String, String) method overload to copy text (.txt) files.

It uses the two overloads of the Copy method as follows: The following example copies files to the C:\archives\2008 backup folder. SourceFileName or destFileName is in an invalid format.
