Filesearch returning files not in alphabetical order?

G

General

Hi,

I have a macro where I do the following:
1) Search for all files in a directory:
Set fs = Application.FileSearch
With fs
.LookIn = dirtosearch
.SearchSubFolders = True
.Filename = "*.*"
.Execute
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
Max = .FoundFiles.Count
for i = 1 to max
list(i) = .foundfiles(i)
next i
******at this point I pause the code
And look at the list array using the watch window, expecting that the
entries are in alphabetical order by the filename.

What I find is it is "almost" in alphabetical order. I found, for
example, the filename for 1213="Mat...", 1214="Man...", 1215="Mat..."!

Help! For my code I need the files to be alphabetized. What am I doing
wrong? Suggestions?

Thanks everyone,

Phil
 
M

Myrna Larson

You're probably not doing anything wrong. With XL2000 and XL2002, I've found
FileSearch to be "flaky" at best, sometimes returning a count of 0 when there
ARE matching files. Bill Manville has, in the past, posted a recursive
Directory routine. I don't know if it alphabetizes the files or not. Search
Google for it. If it doesn't sort them, search also for a QuickSort routine.
 
G

General

ahh crud....that will make things a lot more difficult. Anyone have any
workarounds? Or, any ways to easily alphabetically sort an array? I
can make a 2-D array that has the filename only in one column and sort
on that - I just don't know how to alphabetize an array.

Any help is appreciated.

phil
 
R

RB Smissaert

If you look at the thread API to find file of 21 Feb 05 in this group there
is a routine that I think does get the path names in alphabetical order.
There are plenty of routines around to sort a 1-D or 2-D array. If you can't
find any I am sure somebody can post
one here.

RBS
 
G

General

Thanks everyone.

I ended up parsing the full filename, so in the second column of the
array, I had just the filename.

Then I dumped the array into Excel and sorted by the filename, and then
rewrote everything back into the array. It only took about 1 minute to
do that portion, start to finish, for 35,000 files.

It's REALLY annoying though that the filesearch doesn't really
alphabetize. That's a pretty important detail to screw up - esp since
there's a specific option to sort by filename...Maybe MS will give me
my $$ back? :)

Thanks for everyones help.

Phil
 
M

Myrna Larson

For me it screws up even worse: the file count is returned as 0, when it isn't
0.
 

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