This method does not support wildcard characters in the parameters. Relative path information is interpreted as relative to the current working directory. The sourceFileName and destFileName parameters can specify relative or absolute path information. ' Catch exception if the file was already copied.Ĭatch dirNotFound As DirectoryNotFoundException ' Will not overwrite if the destination file already exists. ' 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. | :? IOException as copyError -> printfn $""ĭ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) Let fName = f.Substring(sourceDir.Length 1)įile.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true)įile.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName)) Let txtList = Directory.GetFiles(sourceDir, "*.txt") Let sourceDir = backupDir = picList = Directory.GetFiles(sourceDir, "*.jpg") Catch exception if the file was already copied.Ĭatch (DirectoryNotFoundException dirNotFound) 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") 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. ![]() Design: .SourceFileName or destFileName is in an invalid format.
0 Comments
Leave a Reply. |