Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Darryl Perez   on Feb 27 In MS Office Category.

  
Question Answered By: Komal Mohammad   on Feb 27

okay... i've kind of made some progress and think this'll work for
the array  comparison, but i have a slightly different problem now...

This is the code  i've come up with:

Private Sub cmdStart_Click()
'check paths exist
If (lblDestPath.Caption = "") Or (lblSrcPath.Caption = "") Or
(txtFilter.Text = "") Then
MsgBox "The Source/Destination folders  or file  Filter don't make
sense!", vbExclamation, "BioFocus DPI : A Galapagos Company"
Exit Sub
End If
'fill initial array
Set RefArray = Application.FileSearch
With RefArray
.LookIn = CStr(lblSrcPath.Caption)
.Filename = CStr(txtFilter.Text)
.Execute SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending
End With
bActive = True
While bActive = True
'sleep
Interval = CInt(cboInterval.ListIndex)
NowTime = Timer
Do While Timer < (NowTime + (Interval * 60))
DoEvents
Loop
'scan source  directory
Set NewArray = Application.FileSearch
With NewArray
.LookIn = CStr(lblSrcPath.Caption)
.Filename = CStr(txtFilter.Text)
.Execute SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending
End With
'compare arrays
For i = 1 To RefArray.FoundFiles.Count
strTemp = Join(RefArray.FoundFiles(i), ",")
Next i
For i = 1 To NewArray.FoundFiles.Count
If StrComp(strTemp, NewArray(i)) Then
'do nothing
Else
'copy file
Set myFSO = CreateObject("Scripting.FileSystemObject")
myFSO.CopyFile NewArray.FoundFiles(i),
CStr(lblDestPath) & " \" & Dir(NewArray.FoundFiles(i))
'do processing bit here....
End If
Next i
'Update RefArray
strTemp = Empty
ReDim RefArray(1 To NewArray.FoundFiles.Count)
For i = 1 To NewArray.FoundFiles.Count
RefArray.FoundFiles(i) = NewArray.FoundFiles(i)
Next i
NewArray = Null
Wend
End Sub

I think this should do the periodic scanning for new filenames, and
also do the copying to the second folder. The bit that i can;t get
working is the last 6 lines before the Wend statement. What i'm
trying to accomplish is to replace the original RefArray with the
values in the NewArray so that the next time the directory  is
scanned, it's comparing  to the penultimate file list  rather than the
very first one  generated. I'm sure it's because the RefArray and
NewArray aren't arrays  that i've specifically declared but the result
of the FileSearch object. Are there any elegant ways to get round
this problem?

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Comparing file lists Or get search suggestion and latest updates.


Tagged: