Page 1 of 1 1
Topic Options
#156487 - 2006-02-02 12:51 PM Compare contents directory
maxranzy Offline
Lurker

Registered: 2006-02-02
Posts: 4
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

Top
#156488 - 2006-02-02 01:51 PM Re: Compare contents directory
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#156489 - 2006-02-02 02:35 PM Re: Compare contents directory
maxranzy Offline
Lurker

Registered: 2006-02-02
Posts: 4
tks, but a tking: where I can find the UDF tools, such DIRPLUS and QSORT??
Top
#156490 - 2006-02-02 02:49 PM Re: Compare contents directory
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
http://kixhelp.com/udfs/
Top
#156491 - 2006-02-02 02:53 PM Re: Compare contents directory
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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


Top
#156492 - 2006-02-02 02:53 PM Re: Compare contents directory
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What's wrong with our own site?
www.kixtart.org/udf
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156493 - 2006-02-02 03:16 PM Re: Compare contents directory
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
it's not in my favorites...as of now.
Top
#156494 - 2006-02-02 03:25 PM Re: Compare contents directory
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156495 - 2006-02-02 04:00 PM Re: Compare contents directory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, dropped it offline when saw the electricity bill
_________________________
!

download KiXnet

Top
#156496 - 2006-02-02 04:46 PM Re: Compare contents directory
maxranzy Offline
Lurker

Registered: 2006-02-02
Posts: 4
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)

Top
#156497 - 2006-02-02 07:44 PM Re: Compare contents directory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
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.
 

Top
#156498 - 2006-02-03 10:17 AM Re: Compare contents directory
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If they are identical you won't see anything.
Top
#156499 - 2006-02-03 02:24 PM Re: Compare contents directory
maxranzy Offline
Lurker

Registered: 2006-02-02
Posts: 4
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

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 447 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.066 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org