Solved

FileSearch.Execute sorting by LastModified does not work

Posted on 2000-05-02
12
438 Views
Last Modified: 2008-03-17
This seems to be a bug in Office. Perhaps there is something I'm overlooking?
While performing a FileSearch, the sort feature works with all but the msoSortByLastModified constant. It reverts to sorting by FileName.

I attached my code below. Is this real or am I missing something?


Sub test()
    Dim ffile As Variant
   
    With Word.Application.FileSearch
        .NewSearch
        .LookIn = "C:\" 'Directory to search
        .FileName = "*.*" 'File types to look for
        .MatchTextExactly = True
        .FileType = msoFileTypeAllFiles
        If .Execute(msoSortByLastModified, 2) > 0 Then    'If matching files are found
            On Error Resume Next
            For Each ffile In .FoundFiles
                Set f = fs.GetFile(ffile)
                Debug.Print (ffile & vbTab & vbTab & FileDateTime(ffile))
            Next ffile
        End If
    End With
   
End Sub
0
Comment
Question by:dhover
  • 7
  • 5
12 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 2771982
Hi dhover,

Las modified means exactly that not created at time...so some logs and thins like autoexec.bat which are changed with installing more doom on the pc will come up above...

:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2772003
this will do it

Sub test()
    Dim ffile As Variant
    Dim fs As FileSearch
    Dim f As Collection
   
   
    With Word.Application.FileSearch
        .NewSearch
        .LookIn = "C:\" 'Directory to search
        .FileName = "*.*" 'File types to look for
        .MatchTextExactly = True
        .FileType = msoFileTypeAllFiles
        If .Execute(msoFileFindSortbyDateSaved, msoSortOrderAscending) > 0 Then             'If matching files are found
            On Error Resume Next
            For Each ffile In .FoundFiles
                Set f = fs.GetFile(ffile)
                Debug.Print (ffile & vbTab & vbTab & FileDateTime(ffile))
            Next ffile
        End If
    End With

HTH:O)Bruintje
0
 
LVL 1

Author Comment

by:dhover
ID: 2773977
Bruintje,
I get the exact same result set as before even when trying it on different machines...Sorted by FileName. Same result for all Office Application objects (Word, Excel, etc...).

Is this isolated to our organization, that is, did it work correctly on your machine?

....After considering your solution further, I realized that msoFileFindSortbyDateSaved is not a valid constant for the FileSearch object. However, the reason it doesn't error out, is because msoFileFindSortbyDateSaved and msoSortByLastModified both evaluate to "4", thereby producing the same results.

Again, does this function work correctly on your machine, or is it an isolated incident, a "random feature"?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2774325
no it does work clean here, otherwise i wouldn't post code...:O)

got a simple office 2k installation here and it worked great....

you got office97?
0
 
LVL 1

Author Comment

by:dhover
ID: 2774641
Sorry, didn't mean to imply that you post bad code, just wanted to make certain...

I've got Office97 SR-2a.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2774725
no offence....:O)

i just thought when i wrote it this morning, and found the types i used above that i never have used this in 97....

Guess what it can't, i got 97 still running besides 2000 and looking at it, you got only 4 types where you've got more then that in 2000

Guess that sort by filedate is your option only with some custom function which i'm now trying to write

:O)Bruintje
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 44

Accepted Solution

by:
bruintje earned 40 total points
ID: 2775131
still got it not running, the logic of keep sorting and the collecton in collection order is stupendously time eating.....

so as alternative why would you use it?

you can print this in a word or excel tabel and sort it there....because building a sorter routine is quite difficult for such a simple thing...

:O)Bruintje
0
 
LVL 1

Author Comment

by:dhover
ID: 2775185
A step ahead of you...

If I were to create a separate routine to do the sorting, I'd populate an ADO Recordset where each record represented a different file. Each property of the file would get it's own field.
Sorting would be a snap and the whole thing would be pretty quick.

Actually, if I were to re-write the application, I'd use the Scripting library's FileSystemObject to read the files and fill the recordset from there. _Much_ quicker than the FileSearch (IMHO).

But, as you mentioned, filling a table in Word is an easy task. And as it turns out, this is exactly what the application does anyway. So this is my work-around.

I just wanted to know for sure if this was a "feature" that everyone had, or just me.

The points are yours.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2775230
hehe, if i knew you was already working with the filesystemobject i would have taken that road earlier.....

think i understated your insights in this stuff and was completely occupied with some wrestlings earlier today at work, building some stock charts took all day, lots of nested if then routines plus an unfriendly activeX control where the sparring partners...

thanks anyway, and take care
0
 
LVL 1

Author Comment

by:dhover
ID: 2775263
Is this what you were using for your "custom function"...the FileSystemObject?

I haven't actually used it a _whole_ lot, but when I have, it seemed much faster than the FileSearch object. What are your observations?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2775377
well i didn't implement it yet fully, but i used it in a little monitor at work to monitor logfiles on remote servers on the network, it was the ease of use, and the properties like being able to open the remote file in a temp file and reading in the last line with time entered etc....and that very fast and accurate.....

I've seen MS promoting the FileSystemObject as a complete replacement for all fileacces operations and system management tools lately.....think they got a point there
0
 
LVL 1

Author Comment

by:dhover
ID: 2775390
Great! Thanks a heap for your insight and help.

dhover
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction It seems that at least a couple of times per month, I answer a question that requires automating Outlook from another Microsoft Office application, usually (although not always) to send one or more email messages.  For example: …
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now