Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


comparing specific files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,41612
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> comparing specific files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 comparing specific files - 1/2/2007 11:27:05 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
hi,

I am just working on a vbscript which used to compare a specif file in a souce folder and destination folder.

Let me explain clearly. I have 2 server 1. Production server and the Backup server.

Everday the new files getting create into the production server for ex.  First day the following files getting created lcms_20071001.bak,master_20071001.bak,prd_20071001.bak. second day the following files getting created lcms_20070201.bak,master_20070201.bak,prd_20070201.bak  Keep on creating every day.

I want to copy the production server files into the backup server. Every week i am copying thru manually. I planned to develop a script. I dont want to copy all the files available in the production server, need to copy only a specific files. for ex. lcms_20071001.bak,lcms_20070201.bak.


I need two things from this script.

1. The specific files which is available in the production server has to update in the destination server i.e. backup server.

2. The Destination  server has to verify the files from the source server. If any files find  in the destination server but  not find in the source server, The files which is available in the destination server has to remove immediately.

I have developed a script, the problem in the script is it used to compare all the files its not taking a specific files.

1. The script is updating all the files from the source server to the destination server 
2. Destination server verify all the file  from the source server any files not available in the source folder the destionation folder gets deleted immediately.

if any one can  help me out to solve this issue it would be great helpful for me.


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objNetwork = wscript.CreateObject("wscript.network")

SOURCE_FOLDER = "\\hpim\e\sourcetest\"

DESTINATION_FOLDER = "\\hplm\d\test_dst\"

ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER

Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath)

Dim aSourceFilearray

Dim aDestinationfilearray

Dim Sourcefilelist

Dim Destinationfilelist

Dim oFileSource

Dim osourcename

Dim osourcefile

Dim oFileDestination

Dim bSourceExists

Dim bDestinationExists

On Error Resume Next

Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath)

Set Sourcefilelist = aSourceFilearray.Files

Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath)

Set FileListDestination = aFileArrayDestination.Files

For each oFileSource in Sourcefilelist

str1= Mid(oFileSource,15,12)

str2 = Mid(oFileSource,27,8)

str3 = Mid(oFileSource,35,4)

If str1 = "lcms_backup_" then

osourcename = str1&str2&str3&".bak"

WScript.Echo osourcename

End If

For each oFileDestination in FileListDestination

bDestinationExists = 0

Set sourcefile = objfso.GetFile(osourcename)

If  sourcefile.Name = oFileDestination.Name then

If sourcefile.DateLastModified = oFileDestination.DateLastModified Then
    
       bDestinationExists = 1

       Exit For
   
     End If

   End If

Next

If bDestinationExists = 0 then

   sourcefile.Copy  strDestinationfolderpath & "\" sourcefile.Name

MsgBox "copy"

End If

Next

For each oFileDestination in FileListDestination

bSourceExists = 0

For each oFileSource in FileListSource

   If oFileDestination.Name = Sourcefile.Name then

     If oFileDestination.DateLastModified = Sourcefile.DateLastModified
then

       bSourceExists = 1

       Exit For

     End If

   End If

Next



If bSourceExists = 0 then

   oFSO.DeleteFile strDestinationfolderpath & "\" oFileDestination.Name,true

End If

Next

msgbox "Files Replicated Successfully"

End Sub


Thanks
Ravi
 
 
Post #: 1
 
 RE: comparing specific files - 1/2/2007 11:58:02 AM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Have you looked at the robocopy.exe utility that comes with the Windows Resource Kit (I think)?  I believe it has all the features you've mentioned, you just need to find the right switch combination for your need.  One of the switches is /MIR which will delete any files in the destination that no longer exist in the source location.  

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Raknahs)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> comparing specific files Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts