ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Application.FileSearch challenge (https://www.excelbanter.com/excel-programming/354965-application-filesearch-challenge.html)

Robin Clay[_4_]

Application.FileSearch challenge
 
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

Tom Ogilvy

Application.FileSearch challenge
 
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

--
Regards,
Tom Ogilvy

"Robin Clay" <Robin_B DOT Clay AT virgin.net wrote in message
...
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




Tom Ogilvy

Application.FileSearch challenge
 
Possibly
http://www.diydatarecovery.nl/chkmate.htm

for your .chk problem.

--
Regards,
Tom Ogilvy

"Robin Clay" <Robin_B DOT Clay AT virgin.net wrote in message
...
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




Robin Clay[_4_]

Application.FileSearch challenge
 
"Tom Ogilvy" wrote:

Possibly
http://www.diydatarecovery.nl/chkmate.htm
for your .chk problem.


Thank you, Tom, for a double helping of your assistance - yet again !

--
Regards

Robin





All times are GMT +1. The time now is 10:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com