The technique of using a search to check in the second array will work, but
has traps. For instance, you are using a comma join to create a big string
of all the file names, but not including those commas in your search. Thus
a search for file "X" will match a file name of "Not X".
You should be searching for comma X comma. But, then you need to handle the
cases of the first and last files. To do this, put a comma at the start and
end of the big string
strTemp = "," & Join(RefArray.FoundFiles(i), ",") & ","
However, your statement looks wrong to me anyway. FoundFiles(i) would be
returning only one file name, and you are overwriting strTemp each time you
go through the loop. I suspect that at the end of the loop, it only has one
file name in it.
You are only doing a one-way check, I think. I.e. you don't look for the
case of a file being deleted from the new array but still being in the ref
array. Don't know whether this is what you want.
You're having trouble with keeping the ref array up to date? At a casual
glance, your code looks sort of OK, although you are ReDim'ing RefArray
rather than RefArray.FoundFiles. My suspicion is that you don't actually
have local arrays containing this information. I think you might be using
structures inside the FSO. So your assignment would not be working or could
be pointing RefArray items into the NewArray structure. Neither would work
properly.
I've just plugged your code into VBE. The ReDim of RefArray is being
rejected by a build - "Invalid ReDim". That's because it isn't an array.
Are you getting this error? If so, I wish you had said so.
(On a matter of naming. I don't think that RefArray or NewArray are
actually arrays. The seem to be structures that contain arrays. I think
you'll find that they are of type FileSearch. You should use Option
Explicit and make sure you define all variables to lessen confusion.)
I suggest you grab the directories lists for both the reference and the new
from FSO each time through the loop. This gets rid of your problem code
completely, and also prevents the directory getting out of step with this
listing - e.g. if someone deletes a file from the reference directory.