I copied code from the link below. It works fine.
How do I recursively copy all files and directories? - vbCity - The .NET Developer Community
I modify code as below and want program working as two goals"
1) If the size of source folder and destination folder are the same, skip;
2) If the size of source folder and destination folder are not the same, only copy different files (my code will copy all files)
But, my code never work as expect. How to modify it?
If fRecursive Then
' Get a list of directories from the current parent.
For Each sDir In System.IO.Directory.GetDirectories(sourceDir)
sDirInfo = New System.IO.DirectoryInfo(sDir)
dDirInfo = New System.IO.DirectoryInfo(destDir & sDirInfo.Name)
' Create the directory if it does not exist.
If dDirInfo.Exists = False Then
dDirInfo.Create()
' Since we are in recursive mode, copy the children also
RecursiveDirectoryCopy(sDirInfo.FullName, dDirInfo.FullName, fRecursive, overWrite)
sDirInfo = Nothing
dDirInfo = Nothing
ElseIf dDirInfo.Exists = True AndAlso GetFolderSize(sourceDir) <> GetFolderSize(destDir) Then
' Since we are in recursive mode, copy the children also
RecursiveDirectoryCopy(sDirInfo.FullName, dDirInfo.FullName, fRecursive, False)
sDirInfo = Nothing
dDirInfo = Nothing[/COLOR]
End If
Next
End If
How do I recursively copy all files and directories? - vbCity - The .NET Developer Community
I modify code as below and want program working as two goals"
1) If the size of source folder and destination folder are the same, skip;
2) If the size of source folder and destination folder are not the same, only copy different files (my code will copy all files)
But, my code never work as expect. How to modify it?
If fRecursive Then
' Get a list of directories from the current parent.
For Each sDir In System.IO.Directory.GetDirectories(sourceDir)
sDirInfo = New System.IO.DirectoryInfo(sDir)
dDirInfo = New System.IO.DirectoryInfo(destDir & sDirInfo.Name)
' Create the directory if it does not exist.
If dDirInfo.Exists = False Then
dDirInfo.Create()
' Since we are in recursive mode, copy the children also
RecursiveDirectoryCopy(sDirInfo.FullName, dDirInfo.FullName, fRecursive, overWrite)
sDirInfo = Nothing
dDirInfo = Nothing
ElseIf dDirInfo.Exists = True AndAlso GetFolderSize(sourceDir) <> GetFolderSize(destDir) Then
' Since we are in recursive mode, copy the children also
RecursiveDirectoryCopy(sDirInfo.FullName, dDirInfo.FullName, fRecursive, False)
sDirInfo = Nothing
dDirInfo = Nothing[/COLOR]
End If
Next
End If