Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using built-in search
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00450592
Message ID:
00450628
Views:
26
>>I really like the search in Windows Explorer. I can search for text in a given date range and it will go into both texfiles and memo fields of tables.
>>
>>Is there any way to programatically use this in VFP? I'd like to feed it a search and have some way of retrieving the list of files it finds.
>>And if you are really keen to roll-your-own then you should check out Filer.DLL - this has all of the functionality of the Windows Explorer search!

Actually, I was going to post a method, which you helped me with while ago. It doesn't allow to specify string and data, may be we can improve it further?
********************************************************************
*  Description.......: FindFileInNetwork
*  Calling Samples...: FindFileInNetwork("pdfmon.dll","c:\")
*  Parameter List....: pcFileToSearch,pcSearchPath, plEntireNetwork
*  Created by........: Houston Brennan 06/13/2000
*  Modified by.......: Nadya Nosonovsky 06/16/2000 11:30:52 AM (with assistance of BP and JH)
********************************************************************
lparameters pcFileToSearch,pcSearchPath, plEntireNetwork
** Check passed parameters

if vartype(pcFileToSearch)<>'C' or empty(pcFileToSearch)
     return .f.
endif

#define NoAttributesSet       0
#define readonly              1
#define hidden                2
#define system                4
#define Archived              32

#define DoNotSearchSubFolder  0
#define SearchSubFolder       1
local i, lcRetPath, lcDrive, lcSearchPath, StartTime,;
         prevonesc, prevescape, msgtail
lcRetPath=''

* note clock reading for generating final timing statistics
StartTime = seconds()                         && # seconds since midnight

* support user Escapes for interrupting the loop
prevonesc = on('escape')                    && save previous Escape handler
prevescape = set('escape')                    && previous Escape enablement state
set escape on                                   && enable escape handling
halt = .f.                                        && allow loop to run until this flag is toggled
on escape halt = .t.                         && force immediate termination if user escapes

* assemble fixed portion of status bar message outside of loop, for speed
msgtail = "...         Wait or press Esc to cancel ..."

wait window nowait 'Searching file '+pcFileToSearch+iif(plEntireNetwork,' in the whole network...',' ...')
oFiler = createobject( "Filer.FileUtil" )
oFiler.FileExpression = pcFileToSearch
oFiler.SubFolder = SearchSubFolder && Search all tree

if vartype(pcSearchPath)<>'C' or (empty(pcSearchPath) and !plEntireNetwork)
     lcSearchPath='c:\' && Local drive
else
    lcSearchPath=pcSearchPath     
endif     

if !plEntireNetwork && Only specified path to search
     oFiler = createobject( "Filer.FileUtil" )
     oFiler.SearchPath = lcSearchPath
     set message to 'Searching in '+lcSearchPath+msgtail
     oFiler.find(0) && Perform search
     if oFiler.files.count>0 && At least one file was found, pick up the first
          lcRetPath=oFiler.files.item[1].path
     endif
else
** Want to search in whole network
     for i = 67 to 90
          lcDrive = chr(i)
          if inlist(drivetype(lcDrive),3,4)
* Make sure the drive is ready (type 4 is either removeable or a network drive)
               set message to 'Searching drive '+lcDrive+msgtail
               oFiler.SearchPath = lcDrive+':\'
               oFiler.find(0) && Perform search
            if m.halt or lastkey()=27 && Escape was pressed
               exit
            endif    
               if oFiler.files.count>0 && At least one file was found, pick up the first
                    lcRetPath=oFiler.files.item[1].path
                    exit
               endif
          endif
     endfor
endif
* Restore settings
set escape &prevescape
on escape &prevonesc
set message to ' '
wait clear
return lcRetPath && Path to the first found file

*!*     FOR iFile = 1 TO oFiler.Files.Count
*!*        ? iFile
*!*        ?? " "
*!*        ?? oFiler.Files.Item[ iFile ].Name
*!*        ?? " "
*!*        ?? oFiler.Files.Item[ iFile ].Attr
*!*        ?? " "
*!*        ?? oFiler.Files.Item[ iFile ].Path
*!*     NEXT iFile
*!*     RETURN .T.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform