I just uploaded a simple PRG called FindTable.  I had a need where I
wanted to find the largest (record count) table on my PC for a given
table name, and so I wrote this PRG to do it.  I have over 150+ folders
on my machine with data from clients that I've acquired because of
testing/fixing data issues for them, so that and this utility made it
easy to locate instances "from the field" where I can see larger record
counts (and hopefully a better sample).

The code is so small that I'll copy it below as well.

-- 
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16


*********************
*** FindTable.prg ***
*********************
LPARAMETERS tcTable, tcPath
LOCAL loFind as cusFindTable OF c:\dev\findtable.prg, lcTable as String,
lcPath as String
IF VARTYPE(tcTable) = "C" AND NOT EMPTY(tcTable) THEN
        lcTable = tcTable
ELSE
        lcTable = "centers"
ENDIF
IF VARTYPE(tcPath) = "C" AND NOT EMPTY(tcPath) THEN
        lcPath = tcPath
ELSE
        lcPath = "c:\symplcty"
ENDIF

* instantiate tool for processing
loFind = CREATEOBJECT("cusFindTable",lcPath,lcTable)
loFind.FindFiles()

* show matches
SELECT curMatches
LOCATE
BROWSE TITLE "Matches for " + lcTable NOEDIT FIELDS cPath :H="Path to
table", dLastModified :H="Date last modified", iFileSize :H="File size
(in bytes)", iRecCount :H="Record Count"
IF RECCOUNT("curProblems")>0 THEN
        SELECT curProblems
        LOCATE
        BROWSE TITLE "Problems encountered while searching for table " +
lcTable NOEDIT
ENDIF
CLOSE ALL
CLEAR ALL


DEFINE CLASS cusFindTable AS Custom
        Name = "cusFindTable"
        cTable = "cntrsch.dbf"
        cDirectory = CURDIR()
        cPath = FULLPATH(CURDIR()) && start path


        PROCEDURE Init(tcDirectory as String, tcTable as String)
                * create temp cursors
                CREATE CURSOR curMatches (cPath c(80), dLastModified d, 
iFileSize i,
iRecCount i)
                CREATE CURSOR curProblems (cPath c(80), cMsg c(80))
                SELECT curMatches
                INDEX on cPath TAG cPath
                INDEX on iRecCount TAG iRecCount DESCENDING
                SET ORDER TO iRecCount

                IF VARTYPE(tcDirectory) = "C" AND NOT EMPTY(tcDirectory) THEN
                        this.cDirectory = tcDirectory
                ENDIF
                IF VARTYPE(tcTable) = "C" AND NOT EMPTY(tcTable) THEN
                        this.cTable = ALLTRIM(tcTable)
                        IF RIGHT(this.cTable,4) <> ".dbf" THEN
                                this.cTable = this.cTable + ".dbf"
                        ENDIF
                ENDIF
                this.cPath = FULLPATH(CURDIR())
        ENDPROC


        FUNCTION FindFiles(tcDirectory as String) as Integer
        * Searches for files and returns match count of cursor.
                LOCAL liNumFiles as Integer, laFiles(1), lcDirectory as String, 
lcDir
as String, liLoop as Integer, loException as Exception
                IF VARTYPE(tcDirectory) = "C" THEN
                        lcDirectory = ADDBS(tcDirectory)
                ELSE
                        lcDirectory = ADDBS(this.cDirectory)
                ENDIF
                CHDIR (lcDirectory)
                liNumFiles = ADIR(laFiles,this.cTable,"") && get actual matches
                FOR liLoop = 1 TO liNumFiles
                        USE IN (SELECT("MyDBF")) && make sure it's closed
                        TRY
                                USE (lcDirectory + this.cTable) IN 0 NOUPDATE 
SHARED AGAIN
ALIAS MyDBF
                                INSERT INTO curMatches (cPath, iFileSize, 
dLastModified, iRecCount)
VALUES (lcDirectory,laFiles(liLoop,2),laFiles(liLoop,3),RECCOUNT("MyDBF"))
                        CATCH TO loException
                                INSERT INTO curProblems (cPath,cMsg) VALUES
(lcDirectory,loException.Message)
                        FINALLY
                                USE IN (SELECT("MyDBF")) && definitely close it
                        ENDTRY
                ENDFOR
                liNumFiles = ADIR(laFiles,"","D") && get subdirs
                FOR liLoop = 1 TO liNumFiles
                        IF NOT INLIST(laFiles(liLoop,1),".","..") THEN
                                lcDir = lcDirectory+laFiles(liLoop,1)
                                this.FindFiles(lcDir)
                        ENDIF
                ENDFOR
                CHDIR (this.cPath)
                RETURN RECCOUNT("curMatches")
        ENDFUNC && FindFiles(tcDirectory as String)

ENDDEFINE && _cusFindTable






_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to