Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

how to return the folder for Application.FileSearch.FoundFiles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muyBN - 28 Jan 2007 19:42 GMT
I need to return the folder in which I find a file with folder for
Application.FileSearch.FoundFiles. It is found in subfolders and from there I
need to know how to find the folder based on the file. Everything I've seen
here does pretty much the reverse. I found something in MS help on "returning
folders" but in actuality it only told about Dir, which returns files in
their examples, not folders. So I have done my homework and I came up with
nada.

Below is my macro code thus far, with comments expressing my frustration.
Thanks in advance for the last piece of the puzzle.

   'returns file's extension, thus allowing me to set a .FileType in the
search
   strFileType = Mid(strFile, InStr(strFile, ".") + 1)
   If strFileType = "xls" Or strFileType = "mdb" Or strFileType = "doc" Or
strFileType = "ppt" Then
       strFileType = msoFileTypeOfficeFiles
   Else
       strFileType = msoFileTypeAllFiles
   End If
   Set fs = Application.FileSearch
   With fs
       .NewSearch
       .FileName = strName 'search for person's name in the file
       .LookIn = "C:\[upper-level folder]"
       .SearchSubFolders = True
       .FileType = strFileType 'use the msoFileType feature provisioned above
       .Execute
       intFiles = .FoundFiles.count
       
       'Loop through the list of found files and return
       'the path of each one to variable strPath
       strDetails = LCase(strName)
       intCnt = 1
       If intFiles > 0 Then
           For intCnt = 1 To intFiles
               If InStr(.FoundFiles.Item(intCnt), strDetails) Then
                   'Break out of the loop
                   intCnt = .FoundFiles.count
                   'return file's path
                   strPath = Dir(.FoundFiles.Item(intCnt))
'ABOVE ONLY RETURNS NAME OF FILE! not the folder
               End If
           Next intCnt
       Else
           MsgBox "No files found."
       End If
   End With
Signature

Bryan

Perry - 28 Jan 2007 20:43 GMT
Parse the foldername from FoundFiles(intCnt), like in:

sFile = .FoundFiles.Item(intCnt)
strFolder = Left(sFile, InstrRev(sFile, ".") -1)

You also use FileSystemObject to loop through files/folders.

Krgrds,
Perry

>I need to return the folder in which I find a file with folder for
> Application.FileSearch.FoundFiles. It is found in subfolders and from
[quoted text clipped - 48 lines]
>        End If
>    End With

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.