FileSearch fails to locate *.jpg and *.tif files

Q

quartz

I am using Office 2003 on Windows XP.

I am using FileSearch to locate files containing certain text. The keyword
text I am searching for is stored in the file properties. This seems to work
okay for MS-Word and MS-Excel (have not tested MS-Access).

But, for *.jpg and *.tif files, the CODE fails to return anything (again the
search text is stored in the file properties). However, if I conduct a MANUAL
search from Windows Explorer, it returns the *.jpg files but not *.tif files.
PLEASE note that a copy of my code follows.

1) Can anyone explain this anomaly and/or fix my code so that this behaviour
will be corrected?

2) Why does the manual search not capture ALL files?

3) I have noticed that some *.jpg and *.tif files do not have accessible
file properties, does anyone know why and how/if I can add file properties to
such files?

Thanks much in advance for your assistance. My function:

Public Function FileSearchText(argSearchText As String, argSearchFolder As
String, argSearchSubFolders As Boolean) As Variant
'RETURNS AN ARRAY OF FULL NAMES OF FILES CONTAINING TEXT SEARCHED FOR;
Dim ofsSearch As FileSearch
Dim ofsFound As FoundFiles
Dim lX As Long
Dim vaFound() As String
Set ofsSearch = Application.FileSearch
With ofsSearch
.NewSearch
.TextOrProperty = argSearchText
.MatchTextExactly = False
.MatchAllWordForms = True
.LookIn = argSearchFolder
.SearchSubFolders = argSearchSubFolders
.FileType = msoFileTypeAllFiles
.Execute
End With
Set ofsFound = ofsSearch.FoundFiles
If ofsFound.Count < 1 Then MsgBox "None found.": End
For lX = 1 To ofsFound.Count
ReDim Preserve vaFound(lX)
vaFound(lX) = ofsFound(lX)
Next lX
FileSearchText = vaFound
End Function
 
J

Jim Thomlinson

Here is the file seach code that I use. It must be referenced to "Microsoft
Scripting Runtime". It has never failed me.

Option Explicit
Option Compare Text

Sub test()
Call ListFiles("C:\Management", Sheet1.Range("A2"), "dbq", True)
End Sub

Public Sub ListFiles(ByVal strPath As String, _
ByVal rngDestination As Range, Optional ByVal strFileType As String = "*", _
Optional ByVal blnSubDirectories As Boolean = False)
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim strName As String

'Specify the file to look for...
strName = "*." & strFileType
Set objFSO = New Scripting.FileSystemObject
Set objFolder = objFSO.GetFolder(strPath)

For Each objFile In objFolder.Files
If objFile.Name Like strName Then
rngDestination.Value = objFile.Path
rngDestination.Offset(0, 1).Value = objFile.DateLastAccessed
Set rngDestination = rngDestination.Offset(1, 0)
End If
Next 'objFile
Set objFile = Nothing

'Call recursive function
If blnSubDirectories = True Then _
DoTheSubFolders objFolder.SubFolders, rngDestination, strName

Set objFSO = Nothing
Set objFolder = Nothing
End Sub


Function DoTheSubFolders(ByRef objFolders As Scripting.Folders, _
ByRef rng As Range, ByRef strTitle As String)
Dim scrFolder As Scripting.Folder
Dim scrFile As Scripting.File
Dim lngCnt As Long

On Error GoTo ErrorHandler
For Each scrFolder In objFolders
For Each scrFile In scrFolder.Files
If scrFile.Name Like strTitle Then
rng.Value = scrFile.Path
rng.Offset(0, 1).Value = scrFile.DateLastAccessed
Set rng = rng.Offset(1, 0)
End If
Next 'scrFile

'If there are more sub folders then go back and run function again.
If scrFolder.SubFolders.Count > 0 Then
DoTheSubFolders scrFolder.SubFolders, rng, strTitle
End If
ErrorHandler:
Next 'scrFolder

Set scrFile = Nothing
Set scrFolder = Nothing
End Function
'-------------------
 
Q

quartz

Many thanks Jim, but it doesn't seem like your functions are constructed to
search for key word text within the files searched. I think I need to use the
"TextOrProperty" property?

OR did you intend that I should adapt your code?
 
J

Jim Thomlinson

It should be easy to adapt. Sorry I should have mentioned that. Change the
optional third argument a little. Right now it looks for

*.<optional argument>

Change it to

*keyword*.file extension

If I understand your requirements correctly that should do it...
 
Q

quartz

I'm sorry Jim, I think I've done a poor job of explaining what I need. I'm
not searching for files by FILENAME, but by key words found in the contents
of the files themselves - specifically in the "Description" field of the file
property - found if you right click on a file name from Windows Explorer and
then click "Properties" and activate the "Summary" tab.

I think your code looks for a keyword within the file name?
 
J

Jim Thomlinson

Sorry I think I may have lead you down the wrong path. File systemm objects
(to the best of my knowledge) don't track the Summary information about
files...
 
Q

quartz

That's okay, half the time I'm on the wrong track anyway, thanks for the
effort...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top