Saturday, February 16, 2013

Sandstorm's Quick Search Tool

Here is another tool to help you search for files in your unit.  You can search multiple types by using asterisk (*) and you can search on multiple locations by either typing the paths straight in the box for Target Folder and/or clicking on the dotted button on the right.

This uses filer.dll that is shipped along with VFP (Home(6)).  For you to be able to use said dll on other machines though, you need to register it first using an admin account.

regsvr32 filer.dll


And here are the codes:


Local oForm As Form
oForm = Createobject('Form1')
oForm.Show(1)
Return

Define Class Form1 As Form
      Height = 470
      AutoCenter = .T.
      Caption = "Sandstorm's Quick Search Tool..."
      Width = 570


      Add Object label1 As Label With ;
            top = 30, Left = 10, Caption = 'Search File', AutoSize = .T.

      Add Object txtFile As TextBox With ;
            top = 28, Left = 100, Value = ''

      Add Object label2 As Label With;
            Top = 60, Left = 10, Caption = 'Target Folder', AutoSize = .T.

      Add Object txtFolder As TextBox With ;
            top = 58, Left = 100, Value = '', Width = 400

      Add Object cmdFolder As CommandButton With;
            top = 56, Left = 505, Caption = '...', Width = 20, Height = 24

      Add Object cmdSearch As CommandButton With;
            top = 85, Left = 10, Caption = 'Start \<Searching',;
            Width = 120, Height = 24

      Add Object chkSub As Checkbox With;
            top = 85, Left = 350, Caption = 'Include Sub Folders',;
            Value = 1, AutoSize = .T.

      Add Object grid1 As Grid With ;
            Top = 120, Left = 10, Height = 300, Width = 550, ColumnCount = 1,;
            deletemark = .F., AllowCellSelection = .F., GridLines = 0, ;
            HeaderHeight = 0, RecordMark = .F., ScrollBars = 2

      Add Object cmdOpen As CommandButton With;
            top = 425, Left = 10, Caption = 'O\<pen File', Width = 120, Height = 24

      Add Object cmdExplore As CommandButton With;
            top = 425, Left = 150, Caption = 'E\<xplore', Width = 120, Height = 24


      Procedure Load
            Create Cursor junk (filename Varchar(250))
            Declare Integer ShellExecute In shell32.Dll ;
                  INTEGER hndWin, String cAction, String cFileName, ;
                  STRING cParams, String cDir, Integer nShowWin
      Endproc

      Procedure cmdFolder.Click
            Local lcFolder, lcFolders
            lcFolder = Getdir()
            lcFolders = Alltrim(Thisform.txtFolder.Value)
            lcFolders = Iif(Empty(m.lcFolders),'',m.lcFolders+';')+m.lcFolder
            * Remove extra ; just in case it was keyed-in as well
            Thisform.txtFolder.Value = Strtran(m.lcFolders,';;',';')
      Endproc

      Procedure grid1.Init
            This.RecordSourceType = 1
            This.RecordSource = 'junk'
            This.Column1.Width = 530
      Endproc

      Procedure cmdOpen.Click
            ShellExecute(0,"open",Alltrim(junk.filename),"","",1)
      Endproc

      Procedure cmdExplore.Click
            ShellExecute(0,"open",'explorer.exe',Justpath(Alltrim(junk.filename)),"",1)
      Endproc

      Procedure cmdSearch.Click
            Local lcFile, lcFolder

            lcFile = Alltrim(Thisform.txtFile.Value)
            * Validate file
            If Empty(m.lcFile)
                  Messagebox('Please type the file to be searched first!',;
                        0+64,'Oppppppssss!')
                  Thisform.txtFile.SetFocus
                  Return(.F.)
            Endif

            lcFolder = Alltrim(Thisform.txtFolder.Value)
            * Validate folder
            If Empty(m.lcFolder)
                  Messagebox('Please Select the folder to be searched first!',;
                        0+64,'Oppppppssss!')
                  Thisform.txtFolder.SetFocus
                  Return(.F.)
            Endif

            lnPaths = Getwordcount(m.lcFolder,';')
            Zap In junk
            For lnCtr = 1 To m.lnPaths
                  lcPath = Getwordnum(m.lcFolder,m.lnCtr,';')
                  Wait Window 'Working on '+m.lcPath+'......' Nowait
                  Thisform.SearchMe(m.lcPath, m.lcFile)
            Next
            Wait Clear
            Go Top
            Thisform.grid1.Refresh
      Endproc

      Procedure SearchMe
            Lparameters lcPath, lcFile
            * start Searching
            Local loFiler As Filer.fileutil, lnloop
            loFiler = Createobject('filer.fileutil')
            With loFiler
                  .SearchPath = m.lcPath
                  .Subfolder = Thisform.chkSub.Value
                  .FileExpression = m.lcFile
                  .Find(0)
                  For lnloop=1 To .Files.Count
                        lcFile = Addbs(.Files(m.lnloop).Path)+;
                              .Files(m.lnloop).Name
                        Insert Into junk Values (m.lcFile)
                  Endfor
            Endwith
            loFiler = .Null.
      Endproc
Enddefine




Cheers!

No comments:

Post a Comment