Application.FileSearch challenge

R

Robin Clay

Greetings !

Here's a snippet from a VBA routine
wot doesn't work as I had hoped / expected :

===================================
.....etc...

'Get the contents of the SOURCE Directory,

Set fsS = Application.FileSearch

With fsS
.LookIn = mySourcePath$
.FileName = "*.*"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending)
= 0 Then
MsgBox "There were no files found."
Else
TotSourceFiles = .FoundFiles.Count
End If
End With

'Get the contents of the TARGET Directory

Set fsT = Application.FileSearch

With fsT
.LookIn = myTargetPath$
.FileName = "*.*"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then
MsgBox "There were no files found."
Else
TotTargFiles = .FoundFiles.Count
End If
End With

'For each file therein,

For N = 1 To TotTargFiles

With fsS
SourceFile = .FoundFiles(N)
End With

myFileName = FileName((SourceFile))

'Check the name against the names in the SOURCE Directory.
For M = 1 To TotSourceFiles

....... etc....
===================================

Why, oh Why, does the fsS set adopt the same values as the fsT set ???

In the Immediate Window, the sets are shown as different sets,
and yet the original values in fsS ar replaced when it reads in values for
fsT.

Be that as it may, my question is, what can I do about it ?


Help?


Regards

Robin Clay
Robin_B DOT Clay AT virgin DOT net
In Dorset's Blackmore Vale
 
T

Tom Ogilvy

There is only one filesearch, you are just creating two references to it.
So when you do you second file search, you are resetting the only
filesearch.

copy out your values to an array before you do the second file search
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top