"RBNUBE" <rbnube at mabenterprises dot com> wrote:
 
> I just put an example together of using the dictionary.  There might be an
> advantage (I think) over arrays in that you do not have to loop through the
> contents of two arrays to compare the two lists of contents.
> 
> This example adds the contents of two folders to two dictionaries.  The
> contents of the dictionaries are compared and the files that are unique to
> each list are added to two different ListBoxes (ListBox1 and ListBox2), one
> being for the unique files in the Source folder and the other for the unique
> files in the Target folder.
> 
> This is NOT recursive.  It was thrown together only as an example.
> 
> Make two properties, SourceDictionary as Dictionary and TargetDictionary as
> Dictionary
> 
> Action event of a PushButton:
> 
>   Dim sourceDictCnt as Integer
>   Dim targetDictCnt as Integer
>   Dim i, h as Integer
>   
>   If SourceDictionary.Count > 0 then
>     sourceDictCnt = SourceDictionary.Count - 1
>     
>     For i = 0 to sourceDictCnt
>       If not TargetDictionary.HasKey(SourceDictionary.Key(i)) then
>         ListBox1.AddRow SourceDictionary.Key(i)
>       End If
>     Next
>   End If
>   
>   If TargetDictionary.Count > 0 then
>     targetDictCnt = TargetDictionary.Count - 1
>     
>     For h = 0 to targetDictCnt
>       If not SourceDictionary.HasKey(TargetDictionary.Key(h)) then
>         ListBox2.AddRow TargetDictionary.Key(h)
>       End If
>     Next
>   End If
> 
> 
> Your main code (the code that parses the directories) could add the path and
> file names as Value and Key pairs to the two dictionaries as it populates
> the two lists.
> 
>   Dim i, sourceCount, targetCount as Integer
>   Dim sourceName, sourcePath as String
>   Dim targetName, targetPath as String
>   Dim sourceFolder, targetFolder as FolderItem
>   Dim sourceDict as New Dictionary
>   Dim targetDict as New Dictionary
>   
>   sourceFolder = DesktopFolder.Child("Test").Child("Source")
>   sourceCount = sourceFolder.Count
>   
>   targetFolder = DesktopFolder.Child("Test").Child("Target")
>   targetCount = targetFolder.Count
>   
>   If sourceCount > 0 then
>     For i = 1 to sourceCount
>       sourceName = sourceFolder.Item(i).Name
>       sourcePath = sourceFolder.Item(i).AbsolutePath
>       SourceList.AddRow sourceName
>       sourceDict.Value(sourceName) = sourcePath
>     Next
>   End If
>   
>   If targetCount > 0 then
>     For i = 1 to targetCount
>       targetName = targetFolder.Item(i).Name
>       targetPath = targetFolder.Item(i).AbsolutePath
>       TargetList.AddRow targetName
>       targetDict.Value(targetName) = targetPath
>     Next
>   End If
>   
>   SourceDictionary = sourceDict
>   TargetDictionary = targetDict

Amazing... Thank you :)

I can't say I fully understand what you're doing, but I'll give it a try
tomorrow and let you know how it goes.

Actually, I do have one question. If the first snippet is under the Action
of a Pushbutton, where would the main code go? Again, sorry for the
n00biness.

P.S. Also, sorry for the Real-NUG subject. This will go back in the proper
thread now.

All My Best,
Jeffrey


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to