I want to write an app that copies files from one directory to another, but only copies files that already exist in the to directory, overwrite them.
Any ideas?
Printable View
I want to write an app that copies files from one directory to another, but only copies files that already exist in the to directory, overwrite them.
Any ideas?
you want to copy files to another directory, but only if they already exist in that ' other ' directory ? so basically you want to write over them?
you can use the System.IO.File.Exists function for this.
VB Code:
Dim files As String() = IO.Directory.GetFiles("C:\Documents and Settings\den\My Documents\My Pictures") For Each s As String In files Dim fileinf As New IO.FileInfo(s) Dim otherpath As String = "C:\" & fileinf.Name If IO.File.Exists(otherpath) Then IO.File.Copy(s, otherpath, True) End If Next
in C#
Code:string[] files = System.IO.Directory.GetFiles(@"C:\Documents and Settings\den\My Documents\My Pictures");
foreach(string s in files)
{
System.IO.FileInfo fileinf = new System.IO.FileInfo(s);
string otherpath = @"C:\" + fileinf.Name;
if ( IO.File.Exists(otherpath) )
{
System.IO.File.Copy(s, otherpath, true);
}
Thanks, easy when you know how.