Solved

FileSearch.Execute sorting by LastModified does not work

Posted on 2000-05-02
12
435 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 44

Accepted Solution

by:
bruintje earned 40 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great! Thanks a heap for your insight and help.

dhover
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
This article will show you how to use shortcut menus in the Access run-time environment.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

7 Experts available now in Live!

Get 1:1 Help Now