Solved

FileSearch.Execute sorting by LastModified does not work

Posted on 2000-05-02
12
441 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

777 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