Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumlist.

Status
Not open for further replies.

beanbrain

Programmer
Dec 31, 2001
170
I'm using Paradox 7.0 and would like to know what ideas others may have regarding enumList. I use this function from time to time to "capture" all the files with a particular pattern. For example if I need to look through a number of files that have a similar naming pattern I'll use this function. However, I've noticed that enumList typically drops the first file name found from a table created from it.

I have a work around to include the first file found but would like to know if anyone else has found a better one.

Thanks in advance.
Bean
 
beanbrain,

I've not had any problems using enumList, provided (of course) you use findFirst() before calling enumList(). As an example, here's a script I use to locate all forms in a directory and any child directories it contains:

Code:
method run(var eventInfo Event)
; ---------------------------------------------------------------
; Searches the working directory and any child directories for
; forms and then ensures that those are saved using stylesheets
; located in a library directory.  This helps prevents style-
; sheet related problems.
; ---------------------------------------------------------------

var
   astrFiles  Array[] String    ; Holds filenames in a directory.
   astrPaths  Array[] String    ; Holds directories to scan.
   dynPieces  Dynarray[] String ; Pieces of the file name.
   fs         FileSystem        ; Pointer to FileSystem routines.
   loRepeat   Logical           ; Flag to continue processing.
   siCounter  SmallInt          ; Loop counter variable
   siNumDirs  SmallInt          ; Counts directories processed
   siNumFrms  SmallInt          ; Counts forms processed
   strDirRpt  String            ; Use to report final count.
   strFileNm  String            ; Current file being processed.
   strFrmRpt  String            ; Use to report final count.
   strValue   String            ; Holds various string values.
endVar

; Note: Constants are declared in the script's Const window.

   ; If you're using a project alias called DATA for your form's
   ; data models, uncomment this section.  (We do this in our
   ; applications; your mileage may vary.)
{
   if getAliasPath( "DATA" ) = "" then
      play( "SETALIAS" )
   endIf
}
   errorTrapOnWarnings( YES )
   astrPaths.addLast( getAliasPath( ":WORK:" ) )
   ignoreCaseInStringCompares( Yes )  ; important for NT
   siNumDirs = 0
   siNumFrms = 0
   loRepeat = TRUE

   while loRepeat

      siNumDirs = siNumDirs + 1    ; increment dir count

      ; Get a list of the files in the working directory,
      ; including ".", "..", and subdirectories.
      fs.findFirst( astrPaths[ 1 ] + "\\*.*" )
      fs.enumFileList( astrPaths[ 1 ] + "\\*.*", astrFiles )

      ; For each file, check its type and then react accordingly.

      for siCounter from 1 to astrFiles.size()
         strFileNm = astrFiles[ siCounter ]

         ; Skip this file and the standard subdirectory
         ; indicators.

         If ( upper( strFileNm ) = SELFNAME ) OR
            ( strFileNm = "." ) OR ( strFileNm = ".." ) then
            loop
         endIf

         splitFullFileName(
            Upper( astrPaths[ 1 ] + "\\" + strFileNm ), dynPieces )

         Message( " (" + String( astrPaths.size() ) + " - " +
                  String( astrFiles.size() - siCounter ) +
                  ") " + "Scanning " + astrPaths[ 1 ] + "\\" +
                  strFileNm )

         setMouseShape( mouseWait )
         switch

            case isDir( astrPaths[ 1 ] + "\\" + strFileNm ) :

               ; If the file is a directory, add its full path
               ; to the directories to process.
               astrPaths.addLast( astrPaths[ 1 ] + "\\" + strFileNm )

            case dynPieces[ "EXT" ] = ".FSL" :

               siNumFrms = siNumFrms + 1
               try
                  verifyForm( astrPaths[ 1 ] + "\\" + strFileNm )
               onFail
                  errorShow( "Can't Open " + strFileNm,
                             "Use [>>] for details..." )
                  if msgQuestion( "Continue?", "Would you " +
                     "like to continue processing your " +
                     &quot;forms?&quot; ) <> &quot;Yes&quot; then
                     loRepeat = FALSE
                     quitLoop
                  endIf
               endTry

         endSwitch
         setMouseShape( mouseArrow )

      endFor

      astrPaths.remove( 1, 1 )  ; &quot;pop&quot; the current dir.

      ; if we haven't already set this to FALSE, then we need
      ; to see if there are other directories to process.
      if loRepeat then
         loRepeat = ( astrPaths.size() > 0 )
      endIf

   endWhile

   ; construct portions of final count message
   if siNumDirs = 1 then
      strDirRpt = &quot; directory &quot;
   else
      strDirRpt = &quot; directories &quot;
   endIf

   if siNumFrms = 1 then
      strFrmRpt = &quot; form &quot;
   else
      strFrmRpt = &quot; forms &quot;
   endIf

   beep()
   Message( &quot;Done!&quot; )
   msgInfo( &quot;Form Styles Fixed&quot;, &quot;For the record:\n\n&quot; +
            string( siNumDirs ) + strDirRpt + &quot;and &quot; +
            string( siNumFrms ) + strFrmRpt +
            &quot;were processed.&quot; )

endMethod

Yes, it's crude. But, hey, it works. If you want a copy of the full script, download the sample file available at which is an article related to this sort of thing.

Hope this helps...

-- Lance
 
The problem I've found is that enumFileList does not capture the first table it finds. I'm not sure why this is. There are fourteen tables in the :label: directory but it only captures the next thirteen. What I've done below to work around this problem is to capture the first table name, it's attributes, and the datetime in order to place this information in the created table myself. It works well, but I'm most interested in why the first table is not in the generated table.

By the way your solution is a good one.

I'm just not sure if this is a bug in Paradox itself or if there is some other way to do this.

var
q query
ts textstream
fs filesystem
tDt datetime
tTm time
div, tName string
tDate, tTime string
tAttrib string
tHr, tMn, tSc smallInt
tSize longInt
tc,tc1 tcursor
endvar


;get list of months available

qtbl = &quot;:labels:LB??????.db&quot;

if fs.findFirst(qtbl) then
tName = fs.name()
tAtt = fs.accessRights()
tSize = fs.size()
tDt = fs.time()
tDate = string(date(tDt))
i = tDate.size()
if i > 9 and tDt.month() < 10 then
tDate = tDate.substr(2,(i - 1))
endIf
i = 0
tHr = tDt.hour()
tMn = tDt.minute()
tSc = tDt.second()
tTime = string(tHr) + &quot;:&quot; + string(tMn) + &quot;:&quot; + string(tSc)

; this is the start of the original code.
; it always dropped the first table in the findFirst above

fs.enumFileList(qtbl, &quot;:pRIV:__filetbl.db&quot;)
tc.open(&quot;:pRIV:__filetbl.db&quot;)
tc.end()

; I added the code below to get the missing table data
; into the generated table.

tc.edit()
tc.nextRecord()
tc.insertRecord()
tc.&quot;Name&quot; = tName
tc.&quot;Size&quot; = number(tSize)
tc.&quot;Attributes&quot; = tAtt
tc.&quot;Date&quot; = tDate
tc.&quot;Time&quot; = tTime
tc.endEdit()
tc.close()
else
msginfo(&quot;Error&quot;,&quot;No files found.&quot;)
return
endif
 
Update. I found the above unnecessary with Paradox 10. Paradox 10 captures all of the file names as specified by the picture. However, despite the fact that the help file states that file names are captured in directory order (as does the Paradox 7.0 help) the orders between the two platforms is different.

By adding an attach and sort to the created table I am able to get the order desired.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top