Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FileSearch.Execute sorting by LastModified does not work

Posted on 2000-05-02
12
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
New style of hardware planning for Microsoft Exchange server.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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