Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default FileSearch fails to locate *.jpg and *.tif files

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default FileSearch fails to locate *.jpg and *.tif files

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default FileSearch fails to locate *.jpg and *.tif files

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?


"Jim Thomlinson" wrote:

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default FileSearch fails to locate *.jpg and *.tif files

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

Jim Thomlinson


"quartz" wrote:

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?


"Jim Thomlinson" wrote:

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default FileSearch fails to locate *.jpg and *.tif files

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?

"Jim Thomlinson" wrote:

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

Jim Thomlinson


"quartz" wrote:

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?


"Jim Thomlinson" wrote:

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default FileSearch fails to locate *.jpg and *.tif files

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

Jim Thomlinson


"quartz" wrote:

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?

"Jim Thomlinson" wrote:

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

Jim Thomlinson


"quartz" wrote:

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?


"Jim Thomlinson" wrote:

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default FileSearch fails to locate *.jpg and *.tif files

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

"Jim Thomlinson" wrote:

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

Jim Thomlinson


"quartz" wrote:

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?

"Jim Thomlinson" wrote:

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

Jim Thomlinson


"quartz" wrote:

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?


"Jim Thomlinson" wrote:

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default FileSearch fails to locate *.jpg and *.tif files

Me too. The trick is trying to figure out which half of the time it is right
now...
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

"Jim Thomlinson" wrote:

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

Jim Thomlinson


"quartz" wrote:

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?

"Jim Thomlinson" wrote:

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

Jim Thomlinson


"quartz" wrote:

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?


"Jim Thomlinson" wrote:

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
'-------------------
--
HTH...

Jim Thomlinson


"quartz" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
filesearch not finding files Kevin Excel Programming 1 January 18th 05 01:49 PM
Filesearch : .zip files not found ??? Benoît HUBERT Excel Programming 1 September 1st 04 06:28 PM
FileSearch dislikes Zip-files Hub van de Laar Excel Programming 4 September 1st 03 08:50 PM
FileSearch dislikes Zip-files Hub van de Laar Excel Programming 0 September 1st 03 06:53 PM
FileSearch dislikes Zip-files Hub van de Laar Excel Programming 0 September 1st 03 06:52 PM


All times are GMT +1. The time now is 04:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"