Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FileSearch.Execute sorting by LastModified does not work

Posted on 2000-05-02
12
Medium Priority
?
448 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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