Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need to do a file search in VFP
Message
 
 
To
11/05/2001 13:11:58
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00506277
Message ID:
00506559
Views:
16
>Does anyone have experience with programmatically performing a file search in VFP based on a top-level directory? This would be similair to what explorer gives you the capability of doing in the find files or computers tool.
>
>The file system object doesn't seem to be up to the task. I could use ADIR but then I have to iterate through all of the sub-direcories under the specified search directory which seems like a lot of work. Perhaps this is my only choice.
>
>Any suggestions?
>
>Thanks for your help!
>
>-JT

There are several files here in Download section including one from Nigel Coates. If this is not for the distribution, you can use Filer.
********************************************************************
*  Description.......: FindFileInNetwork
*  Calling Samples...: FindFileInNetwork("pdfmon.dll","c:\")
*  Parameter List....: tcFileToSearch, tcSearchPath, tlEntireNetwork
*  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 tcFileToSearch, tcSearchPath, tlEntireNetwork
** Check passed parameters
if vartype(tcFileToSearch)<>'C' or empty(tcFileToSearch)
     return .f. && First parameter is required
endif
#define NoAttributesSet       0
#define readonly              1
#define hidden                2
#define system                4
#define Archived              32
#define DoNotSearchSubFolder  0
#define SearchSubFolder       1

local lcRetPath, lcDrive, lcSearchPath, lnStartTime,;
     lcPrevOnEsc, lcPrevEscape, MsgTail, halt, loFiler

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

* support user Escapes for interrupting the loop
lcPrevOnEsc = on('escape')                    && save previous Escape handler
lcPrevEscape = 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 '+tcFileToSearch+iif(tlEntireNetwork,' in the whole network...',' ...')
loFiler = createobject( "Filer.FileUtil" )
loFiler.FileExpression = tcFileToSearch
loFiler.SubFolder = SearchSubFolder && Search all tree

if vartype(tcSearchPath)<>'C' or (empty(tcSearchPath) and !tlEntireNetwork)
     lcSearchPath='c:\' && Local drive
else
     lcSearchPath=tcSearchPath
endif
if !tlEntireNetwork && Only specified path to search
     loFiler.SearchPath = lcSearchPath
     set message to 'Searching in '+lcSearchPath + MsgTail
     loFiler.find(0) && Perform search
     if m.halt or lastkey()=27 && Escape was pressed
          exit
     endif
     if loFiler.files.count>0 && At least one file was found, pick up the first
          lcRetPath=loFiler.files.item[1].path
     endif
else
     local lni, lcDrive
** Want to search in the whole network
     for lni = 67 to 90
          lcDrive = chr(lni)
          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
               loFiler.SearchPath = lcDrive+':\'
               loFiler.find(0) && Perform search
               if m.halt or lastkey()=27 && Escape was pressed
                    exit
               endif
               if loFiler.files.count>0 && At least one file was found, pick up the first
                    lcRetPath=loFiler.files.item[1].path
                    exit
               endif
          endif
     endfor
endif
* Restore settings
if lcPrevEscape='OFF'
     set escape off
endif
on escape &lcPrevOnEsc
set message to ' '
wait clear
=messagebox("File "+iif(!empty(lcRetPath),lcRetPath+tcFileToSearch,"not")+" found in "+ ;
           alltrim(str(seconds()-lnStartTime,10,3))+" sec.")
return lcRetPath && Path to the first found file
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform