|
|
|
Click here to copy the following block | Enum CompareDirectoryEnum cdeSourceDirOnly = -2 cdeDestDirOnly = -1 cdeEqual = 0 cdeSourceIsNewer = 1 cdeSourceIsOlder = 2 cdeDateDiffer = 3 cdeSizeDiffer = 4 cdeAttributesDiffer = 8 End Enum
Function CompareDirectories(ByVal sourceDir As String, ByVal destDir As String) _ As Variant() Dim fso As New Scripting.FileSystemObject Dim sourceFld As Scripting.Folder Dim destFld As Scripting.Folder Dim sourceFile As Scripting.File Dim destFile As Scripting.File Dim col As New Collection Dim index As Long Dim FileName As String Set sourceFld = fso.GetFolder(sourceDir) Set destFld = fso.GetFolder(destDir) If Right$(destDir, 1) <> "\" Then destDir = destDir & "\" ReDim res(1, sourceFld.Files.Count + destFld.Files.Count) As Variant On Error Resume Next For Each sourceFile In sourceFld.Files FileName = sourceFile.Name index = index + 1 res(0, index) = FileName col.Add FileName, FileName Set destFile = fso.GetFile(destDir & FileName) If Err Then Err.Clear res(1, index) = cdeSourceDirOnly Else res(1, index) = cdeEqual Select Case DateDiff("s", sourceFile.DateLastModified, _ destFile.DateLastModified) Case Is < 0 res(1, index) = cdeSourceIsNewer Case Is > 0 res(1, index) = cdeSourceIsOlder End Select If sourceFile.Attributes <> destFile.Attributes Then res(1, index) = res(1, index) Or cdeAttributesDiffer End If If sourceFile.Size <> destFile.Size Then res(1, index) = res(1, index) Or cdeSizeDiffer End If End If Next For Each destFile In destFld.Files If col(destFile.Name) = "" Then index = index + 1 res(0, index) = destFile.Name res(1, index) = cdeDestDirOnly End If Next If index > 0 Then ReDim Preserve res(1, index) As Variant CompareDirectories = res End If
End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|