Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Filesearch object

Status
Not open for further replies.

jacksonmacd

Programmer
Aug 24, 2001
18
CA
Not sure whether this is the right place to ask this question, but here goes:

Trying to put a filesearch object into my PPT97 application. As a test, I am searching for all files with a "7" in the name. Using the Search from Windows Explorer, I can search for files like: *7*.* in a folder, and find several files.

Yet when I repeat the search in the Advanced Search of FileOpen dialog from either Word or PPT, no files are returned. Similarly, the following code snippet returns no files:

Set objSearch = Application.FileSearch
With objSearch
.NewSearch
.PropertyTests.Add Name:="Filename", _
Condition:=msoConditionIncludes, _
Value:="7"
end with

How can I make the filesearch object return the same file list as does Windows Explorer?

Thx


BTW -- I find it ironic/typical/frustrating that the Help for FileSearch says that the Name property corresponds to the Value of the Property Box of the Advanced Search. However, the advanced search uses "file name", while FileSearch object uses "filename". Minor difference, but enough to cause a proram error. Dontcha just love MS consistency??


 
First, you should have posted this to the VBA forum: forum707

The one thing I have noted on the FileSearch object, is that you need to be as explicit as possible when using it because Word is quite "suggestive" when it comes to using it.

Also, because you are using a single search cryteria, it's not necessary to use the PropertyTests collection.

Set objSearch = Application.FileSearch
With objSearch
.NewSearch
'get rid of default propertytest objects
For liCounter = 1 To .PropertyTests.Count
.PropertyTests.Remove liCounter
Next
.FileName = "*7*"
.FileType = msoFileTypeAllFiles
.LookIn = "C:"
.SearchSubFolders = True
.LastModified = msoLastModifiedAnyTime
' other properties etc....
MsgBox "Found " & .Execute(msoSortByFileName) & " Files"
End With

AFA the documentation discrepancy, I think you may be misreading it. The FileSearch object has no Name property; however, a PropertyTest object does. And it's Name property does correlate to the value of the Property field on the advanced search form. Jon Hawkins
 
Correction:

The line of code that reads:
For liCounter = 1 To .PropertyTests.Count

should read:
For liCounter = .PropertyTests.Count To 1 Step -1 Jon Hawkins
 
Jon
thanks for the reply -- and yes, I did realize that for the simple example I provided that the PropertyTests was not required. However, I had viewed it as a first step in figuring out how to do an "AND" search for multiple terms in the filename. The basic filename criteria supports OR by default, but I need AND for the application. Seeing the "connect" operator made me belive that FileSearch object would suit my needs.

Your point about clearing the previous PropertyTest values is appreciated.

After reading your reply, I tried doing another Advanced search in Word, and it turns out that you can't AND multiple terms in the filename. Rats...

This is all in aid of a digital-image storage scheme where the primary subjects of the photo are encoded into the filename. Doing an AND search would be very useful, but I guess it can't be done with the FileSearch object.

Regards to the property name issue -- try this. Open the Advanced Search and start a "name" search. Ctrl-C the string that says "File name". Paste it into my code snippet where you see "filename". It will generate an error, which was my point.

 
AFAIK, the FileName property supports only one search cryteria - you cant use the OR nor AND connector (unless connecting to another property).

FWIW, you can still use wildcards to retrieve the file names if you know the order of the strings you are searching for. IE, "*DIGITAL*7*"

Also, FWIW, the search works fine for me whether I use "FileName" or "File Name". Jon Hawkins
 
>FWIW, you can still use wildcards to retrieve the file >names if you know the order of the strings you are >searching for. IE, "*DIGITAL*7*"


Cool!!! That works. thanks much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top