Link to home
Start Free TrialLog in
Avatar of cutecupid
cutecupid

asked on

Compare DLL using the version

I need to compare the dll's using the version number and copy the latest version number to destination folder.

Ex:

Source:
abc.dll 23/05/2012 1.0.0.14

Source1:
abc.dll 24/05/2012 1.0.0.15

Destination: Copy the source1 dll " Destination
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, I think this should cover the basic requirement.

Regards,

Rob.

strSource = "\\server\share\mydll.dll"
strDestination = "c:\program files\myapp\mydll.dll"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDestination) = True Then
	If objFSO.GetFileVersion(strSource) > objFSO.GetFileVersion(strDestination) Then objFSO.CopyFile strSource, strDestination, True
End If

Open in new window

Avatar of cutecupid
cutecupid

ASKER

Not only to a particular file. I need to check all the files in the listed folder. THat too VBScript I need....thank you
So you have an identical set of DLLs on a server share somewhere for comparison?  If so, then this should work, with folders specified.

Regards,

Rob.

strSource = "\\server\share\myapp\"
strDestination = "c:\program files\myapp\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
If objFSO.FolderExists(strDestination) = True Then
	For Each objFile In objFSO.GetFolder(strSource).Files
		strDestFile = strDestination & objFile.Name
		If objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then objFSO.CopyFile strSource, strDestination, True
	Next
End If

Open in new window

Hi Rob, Thanks for your time and effort...

Fine....

The vbscript should check the dll in the server and desktop or within the desktop from the mnetioned path. Both dll's should get the file revision and compare, if the destination having old dd then it should copy the dll. Then if the dll's is not available in the destination then it should copy from the destination folder. Once the task is completed it should generate log which all files has been copied.
OK, try this.  It will create a log file in the path you specify.

Regards,

Rob.

Set objNetwork = CreateObject("WScript.Network")
strSource = "\\server\share\myapp\"
strDestination = "c:\program files\myapp\"
strLog = "\\server\share\DLLCopyLog_" & objNetwork.ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile(strLog, True)
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
If objFSO.FolderExists(strDestination) = True Then
	If objFSO.FolderExists(strSource) = True Then
		For Each objFile In objFSO.GetFolder(strSource).Files
			strDestFile = strDestination & objFile.Name
			If objFSO.FileExists(strDestFile) = False Then
				objFSO.CopyFile strSource, strDestination, True
				objLog.WriteLine objFile.Path & " was copied to " & strDestFile
			ElseIf objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then
				objFSO.CopyFile strSource, strDestination, True
				objLog.WriteLine objFile.Path & " was copied to " & strDestFile & " because it was newer"
			Else
				objLog.WriteLine objFile.Path & " was not copied to " & strDestFile & " because it was not newer"
			End If
		Next
	Else
		objLog.WriteLine strSource & " was not found."
	End If
Else
	objLog.WriteLine strDestination & " was not found."
End If
objLog.Close

Open in new window

---------------------------
Windows Script Host
---------------------------
Script:      D:\hello\dlltest.vbs
Line:      14
Char:      5
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

Modified Code

Set objNetwork = CreateObject("WScript.Network")
strSource = "D:\hello\Source\"
strDestination = "D:\hello\Destination\"
strLog = "D:\hello\Log_" & objNetwork.ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile(strLog, True)
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
If objFSO.FolderExists(strDestination) = True Then
      If objFSO.FolderExists(strSource) = True Then
            For Each objFile In objFSO.GetFolder(strSource).Files
                  strDestFile = strDestination & objFile.Name
                  If objFSO.FileExists(strDestFile) = False Then
                        objFSO.CopyFile strSource, strDestination, True
                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile
                  ElseIf objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then
                        objFSO.CopyFile strSource, strDestination, True
                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile & " because it was newer"
                  Else
                        objLog.WriteLine objFile.Path & " was not copied to " & strDestFile & " because it was not newer"
                  End If
            Next
      Else
            objLog.WriteLine strSource & " was not found."
      End If
Else
      objLog.WriteLine strDestination & " was not found."
End If
objLog.Close
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, its working fine...Final query on the question
Will it work when comparing 2 different servers folders?
Thanks Rob...Very much appreciated.
No problem. Thanks for the grade.

It will work from any source folder to any destination folder.  For example, if you specify
strSource = "\\servera\masterfiles\"
strDestination = "\\server\backupfiles\"

it will copy the files from the masterfiles folder to the backupfiles folder.

Regards,

Rob.
Hi Rob, Its not comparing the subfolders. Can you pls modify the script for comparing sub folders too.
OK, I've got to run, so I rushed this, but hopefully it works.

Rob.

Set objNetwork = CreateObject("WScript.Network")
strSource = "D:\hello\Source\"
strDestination = "D:\hello\Destination\"
strLog = "D:\hello\Log_" & objNetwork.ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile(strLog, True)
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"

CopyNewerDLLs strSource, strDestination

objLog.Close

Sub CopyNewDLLs(strSourceF, strDestinationF)
	If objFSO.FolderExists(strDestinationF) = True Then
	      If objFSO.FolderExists(strSourceF) = True Then
	            For Each objFile In objFSO.GetFolder(strSourceF).Files
	                  strDestFile = strDestinationF & objFile.Name
	                  If objFSO.FileExists(strDestFile) = False Then
	                        objFSO.CopyFile objFile.Path, strDestFile, True
	                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile
	                  ElseIf objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then
	                        objFSO.CopyFile objFile.Path, strDestFile, True
	                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile & " because it was newer"
	                  Else
	                        objLog.WriteLine objFile.Path & " was not copied to " & strDestFile & " because it was not newer"
	                  End If
	            Next
	      Else
	            objLog.WriteLine strSourceF & " was not found."
	      End If
	      For Each objSubFolder In objFSO.GetFolder(strSourceF).SubFolders
	      	CopyNewDLLs objSubFolder.Path, strDestinationF & objSubFolder.Name & "\"
	      Next
	Else
	      objLog.WriteLine strDestinationF & " was not found."
	End If
End Sub

Open in new window

---------------------------
Windows Script Host
---------------------------
Script:      D:\hello\dlltest.vbs
Line:      10
Char:      1
Error:      Type mismatch: 'CopyNewerDLLs'
Code:      800A000D
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
Sorry, small typo.  On line 10, change this
CopyNewerDLLs strSource, strDestination

to this
CopyNewDLLs strSource, strDestination

Rob.