ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Copy only new or modified files to Directory (Folder) using C# and VB.Net<p>Hi <a class="username" rel="pailwriter"> pailwriter</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">static void Main(string[] args) { string sourcePath = @&#34;C:\Users\anand\Desktop\Test&#34;; string destinationPath = @&#34;C:\Users\anand\Desktop\Test1&#34;; CopyDirectory(sourcePath, destinationPath); } public static void CopyDirectory(string sourcePath, string destinationPath) { DirectoryInfo sourceDir = new DirectoryInfo(sourcePath); FileInfo[] sourceFiles = sourceDir.GetFiles(); for (int source = 0; source &lt; sourceFiles.Length; source++) { DirectoryInfo destinationDir = new DirectoryInfo(destinationPath); FileInfo[] destFiles = destinationDir.GetFiles(); for (int destination = 0; destination &lt; destFiles.Length; destination++) { if (File.Exists(Path.Combine(destinationPath, sourceFiles[source].Name))) { if (sourceFiles[source].Name == destFiles[destination].Name) { if (sourceFiles[source].LastWriteTime &gt; destFiles[destination].LastWriteTime) { sourceFiles[source].CopyTo(Path.Combine(destinationDir.FullName, sourceFiles[source].Name), true); } } } else { sourceFiles[source].CopyTo(Path.Combine(destinationDir.FullName, sourceFiles[source].Name), true); } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Sub Main() Dim sourcePath As String = &#34;C:\Users\anand\Desktop\Test&#34; Dim destinationPath As String = &#34;C:\Users\anand\Desktop\Test1&#34; CopyDirectory(sourcePath, destinationPath) End Sub Public Sub CopyDirectory(ByVal sourcePath As String, ByVal destinationPath As String) Dim sourceDir As DirectoryInfo = New DirectoryInfo(sourcePath) Dim sourceFiles As FileInfo() = sourceDir.GetFiles() For source As Integer = 0 To sourceFiles.Length - 1 Dim destinationDir As DirectoryInfo = New DirectoryInfo(destinationPath) Dim destFiles As FileInfo() = destinationDir.GetFiles() For destination As Integer = 0 To destFiles.Length - 1 If File.Exists(Path.Combine(destinationPath, sourceFiles(source).Name)) Then If sourceFiles(source).Name = destFiles(destination).Name Then If sourceFiles(source).LastWriteTime &gt; destFiles(destination).LastWriteTime Then sourceFiles(source).CopyTo(Path.Combine(destinationDir.FullName, sourceFiles(source).Name), True) End If End If Else sourceFiles(source).CopyTo(Path.Combine(destinationDir.FullName, sourceFiles(source).Name), True) End If Next Next End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/166820/Copy-only-new-or-modified-files-to-Directory-Folder-using-C-and-VBNet/https://www.aspforums.net:443/Threads/166820/Copy-only-new-or-modified-files-to-Directory-Folder-using-C-and-VBNet/Mon, 25 Mar 2019 05:54:20 GMT