maxranzy
(Lurker)
2006-02-02 12:51 PM
Compare contents directory

Hi,
I need to compare recursivly the contents of two folder, but I don't understand how can I do.
I don't know in advance which file or directory are inside the directory, so I have to check in a "master" directory it's content and verify if a "slave" directory content is the same.
Someone can help me??

Max


Richard H.Administrator
(KiX Supporter)
2006-02-02 01:51 PM
Re: Compare contents directory

There are recursive DIRs available in the UDF forum - a quich search should turn these up.

The process is actually pretty simple.

  • Get a recursive list of master dir
  • Get a recursive list of slave dir
  • Sort both - the Qsort() udf is good for this
  • Compare the lists side-by-side. If entry in list1 > entry in list2 then entry is missing from list 1 and vice-versa.


maxranzy
(Lurker)
2006-02-02 02:35 PM
Re: Compare contents directory

tks, but a tking: where I can find the UDF tools, such DIRPLUS and QSORT??

maciep
(Korg Regular)
2006-02-02 02:49 PM
Re: Compare contents directory

http://kixhelp.com/udfs/

Richard H.Administrator
(KiX Supporter)
2006-02-02 02:53 PM
Re: Compare contents directory

And here is an example of how you can compare the two lists once they are sorted:
Code:
Break ON
udfCompare(Split("a b d2 c e"),Split("b d1 e f g h"))

Function udfCompare($avList1,$avList2)
Dim $iIndex1,$iIndex2
$iIndex1=0
$iIndex2=0
While $iIndex1<=UBound($avList1) OR $iIndex2<=UBound($avList2)
Select
Case $iIndex1>UBound($avList1)
$udfCompare=$udfCompare+@CRLF+$avList2[$iIndex2]+" missing from list 1"
$iIndex2=$iIndex2+1
Case $iIndex2>UBound($avList2)
$udfCompare=$udfCompare+@CRLF+$avList1[$iIndex1]+" missing from list 2"
$iIndex1=$iIndex1+1
Case $avList1[$iIndex1] > $avList2[$iIndex2]
$udfCompare=$udfCompare+@CRLF+$avList2[$iIndex2]+" missing from list 1"
$iIndex2=$iIndex2+1
Case $avList2[$iIndex2] > $avList1[$iIndex1]
$udfCompare=$udfCompare+@CRLF+$avList1[$iIndex1]+" missing from list 2"
$iIndex1=$iIndex1+1
Case "Match"
$iIndex1=$iIndex1+1
$iIndex2=$iIndex2+1
EndSelect
Loop
$udfCompare=SubStr($udfCompare,3)
EndFunction



Les
(KiX Master)
2006-02-02 02:53 PM
Re: Compare contents directory

What's wrong with our own site?
www.kixtart.org/udf


maciep
(Korg Regular)
2006-02-02 03:16 PM
Re: Compare contents directory

it's not in my favorites...as of now.

Les
(KiX Master)
2006-02-02 03:25 PM
Re: Compare contents directory

I just wish they would have standardized the mirrors to the mothership. KORG is in /udf/, Ron's in /udfs/, and Bryce's is udf.isorg.com. Not sure about Lonk's... the URL jokeli.isa-geek.com/UDF linked from Bryce's mirror no worky.

LonkeroAdministrator
(KiX Master Guru)
2006-02-02 04:00 PM
Re: Compare contents directory

ja, dropped it offline when saw the electricity bill

maxranzy
(Lurker)
2006-02-02 04:46 PM
Re: Compare contents directory

Ok, ok

I tried to use these function udfCompare and Dirplus for check two directories quiet different, but I didn't see any result......
What's wrong?
this is the script

$dirNameSlave = "C:\Temp\dirA"
$dirNameMaster = "C:\Temp\dirB"

$filesSlave = Dirplus($dirNameSlave, '/s')
$filesMaster = Dirplus($dirNameMaster, '/s')

udfCompare($filesSlave,$filesMaster)


NTDOCAdministrator
(KiX Master)
2006-02-02 07:44 PM
Re: Compare contents directory

Think you need to read up on using KiXtart and UDF in general, you can't just call a UDF and then not tell the script what to do with the returned data. That aside... what do you want to do with this information once you have it?

If you're wanting to MIRROR folders/drives then ROBOCOPY would be much better at automatically handling this for you and it too is FREE.
 


Richard H.Administrator
(KiX Supporter)
2006-02-03 10:17 AM
Re: Compare contents directory

If they are identical you won't see anything.

maxranzy
(Lurker)
2006-02-03 02:24 PM
Re: Compare contents directory

Hi,

I don't want mirror the master dir in slave dir, but only check the difference (richard, the directories are different..).

I wrote this function and seems that the result are ok, what do you think about that?

$dirNameSlave = "C:\Temp\dirA"
$dirNameMaster = "C:\Temp\dirB"

dirCompare($dirNameMaster, $dirNameSlave)

Function dirCompare($masterPath, $slavePath)

$filesSlave = Dirplus($slavePath, '/s')
$lenSlavePath = len($slavePath)

For Each $file in $filesSlave

If Not (exist($masterPath + right($file, len($file) - $lenSlavePath)))
? "The path " + right($file, len($file) - $lenSlavePath - 1) + " doesen't exist in " + $masterPath
Endif

Next

EndFunction