"Joseph J. Strout" <[EMAIL PROTECTED]> wrote:

> 
>> I get a nilObject at this line:
>> 
>>  TargetName = TargetFolder.trueitem(indexT).DisplayName
> 
> Well, this doesn't seem surprising to me -- indexT is not looping
> over the contents of TargetFolder, but rather of currentFolderT:
> 
>      for indexT = currentFolderT.Count DownTo 1
> 
> I haven't taken the time to fully understand your code, but it's
> usually a mistake to be looping over the indices of one folder, but
> trying to use those indices in a different folder.  Seems like you
> should either be looping from TargetFolder.Count, or getting items
> from currentFolderT.
> 
> Also, your code will be clearer, somewhat faster, and easier to debug
> if you introduce a temporary variable to represent each item:
> 
>     Dim item As FolderItem = TargetFolder.TrueItem(indexT)
>     TargetName = item.DisplayName
>     TargetPath = item.ShellPath
> 
> 
> HTH,
> - Joe

Hi, Joe--

I actually lifted this snippet from Seth Willits' ResExcellence article on
recursion (http://www.resexcellence.com/realbasic/articles/2003/10-21-03/)

He had a variable which he was using to do the selectFolder he named
rootFolder. I simply replaced his variable with mine, targetFolder, in any
places in the code where it existed, then let the rest of his code stand as
is.

When I replaced curentFolderT with TargetFolder -- which certainly seems
like the correct way to do this, once you pointed it out -- the nilObject no
longer occurs. So, thank you :)

However, now the comparison is failing. Instead of finding the correct
missing items, which in this case should have been 17, it is stating that
the target is missing 44 items, and when their displaynames are checked in
the listbox, all but the original 17 files listed as missing, do in fact
exist in the target folder.

Here's the code doing the comparison to find the missing files. First, the
corrected code which adds the items in Source and Target to the
corresponding listboxes and dictionaries. Each is identical except the
change in variables for "source" and "target", so I'll only reproduce the
target routine here:

    targetFolder = SelectFolder()
  if targetFolder = nil then return

// Add rootFolder to stack
  foldersT.Append targetFolder
  
  // For each folder in the stack
  while UBound(FoldersT) > -1
    // Get the folder at the top of the stack
    targetFolder = foldersT.Pop
    
    // For each item in the current folder
    for indexT = targetFolder.Count DownTo 1
      itemInFolderT = targetFolder.trueitem(indexT)
      if itemInFolderT <> nil then
        
        // If item is a folder
        if itemInFolderT.Directory = true then
          // Add folder to the stack
          foldersT.Append itemInFolderT
          
        else
          // Add file to the listbox
          ItemT= TargetFolder.TrueItem(indexT)
          TargetName = itemT.DisplayName
          TargetPath = itemT.ShellPath
          TargetList.AddRow TargetName
          TargetDict.Value(TargetName) = TargetPath
         
        end if
      end if
    next
  wend


Then the code which does the comparison and adds the missing files to the
target listbox:


  SourceDictionary = sourceDict
  TargetDictionary = targetDict
  
  //Find missing files in the Dictionaries
  If SourceDictionary.Count > 0 then
    sourceDictCnt = SourceDictionary.Count - 1
    
    For j = 0 to sourceDictCnt
      If not TargetDictionary.HasKey(SourceDictionary.Key(j)) then
        c=SourceDictionary.Key(j)
        TargetList.AddRow c
        missing=missing+1
      End If
    Next
  End If
  

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