Hello evryone,
This is my first post, so, i use a vbscript in the onExecute action event, this script contain two sub statement, "compareFiles( , ) " and "compareFolders( , )" these are in the global project script.
The "compareFolders" sub is calling compareFiles and is recursive. When i validate the project there is no errors, when i run the project evrything is "GREEN", but nothing happen, it looks like the call compareFolders in the onexecute event is not done.
Here is the script in the OnExecute event (all the variables are defined in the edit variables menu) :
'Option Explicit
'the object file sysytem
'Dim oFSO
'create an instance of FileSystemObject
set oFSO = createObject("Scripting.FileSystemObject")
'the folders paths
'Dim oFoldS, oFoldR, p_oFoldS, p_oFoldR
'the subfolders paths
'Dim oSubFoldS, oSubFoldR, p_oSubFoldS, p_oSubFoldR
'the files of each subfolder
'Dim oFileS, oFileR
' The resume file
'Dim oFileResume
' The file that will be contain all the files for winmerge
'Dim fichier
'the name of the current ... in the "for each" loop
'Dim fileNameS, fileNameR, filePathS, filePathR, fileParentPathS, fileParentPathR, sameNameR, samePathR, sameParentPathR
'Dim sameSizeR, sameDateLastModifiedR, targetPath
'the model and the variables of the regular expression
'Dim model, match, matches, xcopyPath, convertXcopy, convertedPathS, repExist
Set model = New RegExp
Set xcopyPath = New RegExp
Set convertXcopy = New RegExp
model.pattern = "^.*\.(?!(dll|exe|iii|ddd|bin|.*~|zip)$).*$"
' First i change the \ to \\ so the regular expression will work
' open file mode options
'Const ForWriting = 2, ForReading = 1, ForAppending = 8
' The first line of the report
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "Side" & vbTab & "ParentFolder " & vbTab & "File Name " & vbTab & "Type " & vbTab & "Action " & vbTab & "Comment" & vbCrlf
oFileResume.close
' The shell to lauch the fc command line
'Dim oShell, boolCompare,boolXcopy, boolTestName
Set oShell = CreateObject("WScript.Shell")
set oFoldS = oFSO.getFolder(sergeyPathCurrent)
'set oFoldS = oFSO.getFolder(".\testBATCH")
'Set p_oFoldS = oFSO.getFolder(".\testBATCH")
set oFoldR = oFSO.getFolder(rachellePathCurrent)
Call compareFolders(oFoldS,oFoldR)
here is the compareFolders sub that is in global script project :
Sub compareFolders(p_oFoldS, p_oFoldR)
On Error Resume Next
Call compareFiles(p_oFoldS,p_oFoldR)
If p_oFoldS.SubFolders.Count <> 0 And p_oFoldR.SubFolders.Count = 0 Then
For Each p_oSubFoldS In p_oFoldS.SubFolders
Call compareFolders(p_oSubFoldS,p_oFoldR)
Next
ElseIf p_oFoldS.SubFolders.Count <> 0 And p_oFoldR.SubFolders.Count <> 0 Then
For Each p_oSubFoldS In p_oFoldS.SubFolders
repExist = False
For Each p_oSubFoldR In p_oFoldR.SubFolders
If p_oSubFoldS.Name = p_oSubFoldR.Name Then
Call compareFolders(p_oSubFoldS,p_oSubFoldR)
repExist = True
End If
Next
If Not repExist Then
convertXcopy.Pattern = "\\+"
convertXcopy.Global = True
convertedPathS = ""
convertedPathS = convertXcopy.Replace(p_oFoldS.Path,"\\")
xcopyPath.Pattern = "[^(" & convertedPathS & ")].*"
Set matches = xcopyPath.Execute(p_oSubFoldS.Path)
For Each match In matches
targetPath = match.Value
Next
boolXcopy = oShell.Run ("xcopy.exe /S /Y " & p_oSubFoldS.Path & " " & p_oFoldR.Path & "\" & targetPath & "\", 0, True)
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "S" & vbTab & p_oSubFoldS.Path & vbTab & p_oSubFoldS.Name & vbTab & " tree " & vbTab & " created" & vbTab & " new folder" & vbCrlf
oFileResume.close
End If
Next
End If
End Sub
here it is the compareFiles sub in the global script project :
Sub compareFiles(p_oFoldS,p_oFoldR)
Action = True
For Each oFileS in p_oFoldS.Files
fileNameS = oFileS.Name
filePathS = oFileS.Path
fileParentPathS = oFileS.ParentFolder
if oFileS.Size <> 0 then ' sergey file size not zero
boolTestName = False
For Each oFileR in p_oFoldR.Files
fileNameR = oFileR.Name
filePathR = oFileR.Path
fileParentPathR = oFileR.ParentFolder
If fileNameR = fileNameS Then
boolTestName = True
sameNameR = fileNameR
sameParentPathR = fileParentPathR
samePathR = filePathR
sameSizeR = oFileR.Size
sameDateLastModifiedR = oFileR.DateLastModified
End if
Next
if boolTestName then ' not new sergey file
If sameSizeR <> 0 then ' rachelle file size not zero
If model.Test(fileNameS) then 'ascii file
boolCompare = oShell.Run("fc.exe /L " & filePathS & " " & samePathR, 0, True)
if boolCompare <> 1 then 'the ASCII files are the same
oFSO.CopyFile filePathS,samePathR,True
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " ASCII " & vbTab & " copied" & vbTab & " same" & vbCrlf
oFileResume.close
else 'the ASCII files are different
set fichier = oFSO.OpenTextFile("C:\Users\zine\Desktop\extension.txt",ForAppending,True, -2)
fichier.write("/e " & samePathR & " " & filePathS & vbCrlf)
fichier.Close
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " ASCII " & vbTab & " winmerge" & vbTab & "different" & vbCrlf
oFileResume.close
end if
else 'bin files
boolCompare = oShell.Run("fc.exe /B " & filePathS & " " & filePathR, 0, True)
if boolCompare <> 1 then 'the BIN files are the same
oFSO.CopyFile filePathS,samePathR,True
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " BIN " & vbTab & " copied" & vbTab & " same" & vbCrlf
oFileResume.close
else 'the BIN files are different
if oFileS.DateLastModified > sameDateLastModifiedR then
oFSO.CopyFile filePathS,samePathR,True
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " BIN " & vbTab & " copied" & vbTab & "newer" & vbCrlf
oFileResume.close
end if
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " BIN " & vbTab & " not copied" & vbTab & "older" & vbCrlf
oFileResume.close
end if
end If
Else ' rachelle file size zero
oFSO.CopyFile filePathS,oFileR.Path,True
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
if model.Test(fileNameS) then ' ascii file
oFileResume.write "R" & vbTab & fileParentPathR & vbTab & fileNameR & vbTab & " ASCII " & vbTab & " copied" & vbTab & " R zero but S not zero" & vbCrlf
oFileResume.close
else 'bin file
oFileResume.write "R" & vbTab & fileParentPathR & vbTab & fileNameR & vbTab & " BIN " & vbTab & " copied" & vbTab & " R zero but S not zero" & vbCrlf
oFileResume.close
end If
End if
else ' it is a new file in Sergey directory
convertXcopy.Pattern = "\\+"
convertXcopy.Global = True
convertedPathS = ""
convertedPathS = convertXcopy.Replace(oFoldS.Path,"\\")
xcopyPath.Pattern = "[^(" & convertedPathS & ")].*"
Set matches = xcopyPath.Execute(oFileS.ParentFolder.Path)
For Each match In matches
targetPath = match.Value
Next
If p_oSubFoldR = Empty Then
boolXcopy = oShell.Run ("xcopy.exe /S /Y " & filePathS & " " & oFoldR.Path & "\" & targetPath & "\", 0, True)
else
boolXcopy = oShell.Run ("xcopy.exe /S /Y " & filePathS & " " & p_oSubFoldR.Path & "\", 0, True)
End if
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
if model.Test(fileNameS) then 'ascii file
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " ASCII " & vbTab & " created" & vbTab & " new file" & vbCrlf
oFileResume.Close
else 'bin file
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " BIN " & vbTab & " created" & vbTab & " new file" & vbCrlf
oFileResume.close
end if
end if
else ' sergey file size is zero
set oFileResume = oFSO.OpenTextFile(".\RESUME.txt",ForAppending,True,-2)
if model.Test(fileNameS) then ' ascii file
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " ASCII " & vbTab & " not copied" & vbTab & " size zero" & vbCrlf
oFileResume.close
else 'bin file
oFileResume.write "S" & vbTab & fileParentPathS & vbTab & fileNameS & vbTab & " BIN " & vbTab & " not copied" & vbTab & " size zero" & vbCrlf
oFileResume.close
end if
end if
Next
End Sub