Re: Find files are SYN or Not in Two Folders




"ashoksganesh" <ashoksganesh@xxxxxxxxx> wrote in message
news:be7fd49f-8588-47d1-997c-7fb26c75df12@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mar 17, 7:23 pm, "Paul Randall" <paul...@xxxxxxx> wrote:
"ashoksganesh" <ashoksgan...@xxxxxxxxx> wrote in message

news:329799c3-5728-4bc3-93b1-c0d8e61cb942@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx





Here wat am trying to acheive.

1) I have a Folder A and Folder B.
"
2)i want to check the files are sync in Folder A and Folder B,using
time frame

Now what am trying to do is

1)check the file in FolderA and grab the files from 9Am to 12 Pm go to
Folder B and find the file is exist or not.
2)This script should run every three hours to find the syn or non sync
between FolderA and Folder B files.

definitely there should be some easy way to do this,but i checked
different forum,i didn't get a right way to pursuit this,please help
me to
solve this issue.

Thanks in Advance

Here is the one i wrote just for count

****************************************************************
Dim oFS, SourceFolder,DestFolder,Source,Dest,demofolder,foldername
set oFS =CreateObject("Scripting.FileSystemObject")
set SourceFolder = oFS.GetFolder("c:\sourcefolder")
Set DestFolder=oFS.GetFolder("c:\destfolder")
foldername=demofolder.Name
Source= SourceFolder.Files.Count
Dest= DestFolder.Files.Count
If Source=Dest Then
WScript.Echo "SYNC"
Else
WScript.Echo "NON SYNC"
End if

******************************************************************

Not sure how to insert time frame in this script,please lead me.

Thanks

It is relatively easy to script checking that all files that exist in
sourcefolder also exist in destfolder, and maybe you would also have to
verify that all files in dest folder also exist in source folder. This
does
not mean that the files are identical, only that they exist.

Perhaps you need some way to verify the files are actually the same.
Microsoft has a tool to help with this
task.http://www.microsoft.com/downloads/details.aspx?FamilyID=B3C93558-31B...
FCIV is a command line tool which can produce SHA1 or MD5 checksums for
all
the files in a folder and its subfolders. Alternately, it can produce an
XML-formatted text file with checksum info. Later, FCIV can then use this
XML file as input when the tool is used to verify that everthing listed in
the XML file exists identically in the original or some other folder. The
script could be set up to read STDOUT while the command line is executed,
and and report any problems.

If you are interested in this, post a reply here and I will clean up and
post a sample script.

-Paul Randall- Hide quoted text -

- Show quoted text -

Hey Paul,

Sorry for the late reply,already i strat using FCIV (the code created
by EHVBS)in the script,but wat am tring to achieve here is

Use the date range or today's date file to compare and ignore the
previous day's files.

Here is the scritp :

**********************************************************************************************************

Dim oFS : Set oFS = CreateObject
( "Scripting.FileSystemObject" )
Dim aDirs : aDirs = Array( ".\sourcefolder", ".\destfolder" )
Dim dicGrps : Set dicGrps = CreateObject( "Scripting.Dictionary" )
Dim fncClas : Set fncClas = GetRef( "getIdentityOfFile" )
Dim sDir
For Each sDir In aDirs
' WScript.Echo "processing", sDir
Dim oFiles : Set oFiles = oFS.GetFolder( sDir ).Files
Dim oFile
For Each oFile In oFiles
' WScript.Echo " processing", oFS.GetBasename( oFile.Name ),
oFile.Path
Dim sProp : sProp = fncClas( oFile )
If Not dicGrps.Exists( sProp ) Then
dicGrps.Add sProp, CreateObject( "Scripting.Dictionary" )
' WScript.Echo " adding property/group", sProp, "to
dictonary"
End If
dicGrps( sProp )( oFile.Path ) = 0
'WScript.Echo " adding file ", oFile.Path, "to dictionary
for property", sProp
Next
Next

Dim bSync : bSync = True
Dim sKey, aKeys
For Each sKey In dicGrps.Keys
If 1 = dicGrps( sKey ).Count Then
aKeys = dicGrps( sKey ).Keys
WScript.Echo " Group", sKey, aKeys( 0 )
bSync = False
End If
Next
If Not bSync Then
WScript.Echo Join( aDirs, ", " ) & " Files are not in sync"
Else
WScript.Echo Join( aDirs, ", " ) & "All Files are SYNC"
End If
Function getIdentityOfFile( oFile )
Dim oShell : Set oShell = WScript.CreateObject( "WScript.Shell" )
Dim sCmd : sCmd = "fciv -add """ & oFile.Path & """ -md5"
' WScript.Echo sCmd
Dim sDigest : sDigest = oShell.Exec( sCmd ).Stdout.ReadAll
WScript.Echo sDigest
Dim aParts
aParts = Split( sDigest, vbCrLf )
sDigest = Left( aParts( UBound( aParts ) - 1 ), 32 )
WScript.Echo sDigest
getIdentityOfFile = sDigest
End Function

-------------------------------------------------------------------------------
As I understand it, you now need a way to tell whether a file was created
within a specific span of time (9Am to 12 Pm ) today. That is easy. Try
the following script:

Option Explicit
Dim oFS: Set oFS = CreateObject("scripting.filesystemobject")
Dim DateCreated, fDateCreated
fOverWriteA "dummy.txt", "a"
Dim oFile: Set oFile = oFS.GetFile("dummy.txt")
DateCreated = oFile.DateCreated
MsgBox "DateCreated = " & DateCreated & vbCrLf & _
"Floating Point version = " & CDbl(DateCreated)

Sub fOverWriteA(sFileName, sAnsiText)
CreateObject("Scripting.FileSystemObject")._
CreateTextFile(sFileName, True, False)._
Write(sAnsiText)
End Sub

A file's Time/Date can be represented as a floating point number, where the
fraction part is the fraction of a 24-hour day, and the whole number part is
the number of days since VBScript time zero. The Now function gives you the
time/date right now. If this script may be started shortly before midnight,
you may want to get today's day number when the script starts. Getting it
repeatedly as the script runs may confuse things if the script continues
past midnight.

Your logic for comparing the files of interest seems overly complex with its
nested dictionaries, but it seems to work for very simple folders. Also, I
don't understand the need for a reference to the function rather than
accessing the function directly :
Dim fncClas : Set fncClas = GetRef( "getIdentityOfFile" )

-Paul Randall


.



Relevant Pages

  • Re: Script to create subdirectories
    ... Then the rest of the script (i.e. the Function that I posted, ... Dim aFolders, newFolder ... ' Splits the various components of the folder name. ...
    (microsoft.public.windows.server.scripting)
  • Re: map web folder
    ... I ran through the creation script one time today and it worked like a charm! ... until then here is the script to create a web folder ... Dim iRes, jRes, MT, TT ... bString = bString & Chr ...
    (microsoft.public.scripting.wsh)
  • Re: Create OU and users with VBS and Excel
    ... OU each user should be created in, and what profile path to use. ... However, if you want to automate this all in one script, read the OU ... cacls command to assign privileges for the folder to the new user object. ... Dim objRootLDAP, objContainer, objUser, objShell ...
    (microsoft.public.scripting.vbscript)
  • Re: Rolling back folders delete using VBA
    ... created at run time) with same sub folder structure. ... if we come accross an error while deleting a file from original location. ... Dim oSubFolder As Object ... Dim oFile As Object ...
    (microsoft.public.excel.programming)
  • Re: help with error checking in code NEWBIE
    ... Below is the entire script again with an error check for creating the ... in each folder on your C Drive? ... Dim intFOL ...
    (microsoft.public.scripting.vbscript)