Here is the stored procedure I use for getting a directory of files into 
R:Base.  You call it specifying the name of a table into which you want the 
results loaded, a search spec (with wildcards, or whatever), and a Y/N flag as 
to whether you want directories included in the results.

The code will create the table as necessary (as a TEMP table), load the results 
using the DIR-to-filename technique, then clean up the resulting table so it 
contains only the records you want.  You can then use the data in the table any 
way you want.  It returns the number of files found.

SET VAR tFileCount = (CALL GetFiles('tFileTbl', 'C:\RBTI\RBG76\*.CHM', 'N'))

The code to "load" the procedure into the database is in the comment in the 
file.
--
Larry

-----------------------------------------------------------------------------
-- GetFiles.PRC
-----------------------------------------------------------------------------
-- PUT GetFiles.PRC AS GetFiles pGF_Table TEXT(18) pGF_Spec TEXT(100) 
pGF_WithDirs TEXT(1) RETURN INTEGER

IF pGF_Table IS NULL OR pGF_Spec IS NULL THEN
  RETURN 0
ENDIF

SET ERROR MESSAGE 2038 OFF
DROP TABLE &pGF_Table
SET ERROR MESSAGE 2038 ON

CREATE TEMP TABLE &pGF_Table ( +
  tFileDate DATE, +
  tFileTime TIME, +
  tDirFlag  TEXT(5), +
  tFileSize INTEGER, +
  tFileName TEXT(100), +
  tSelectFile TEXT(1) DEFAULT 'N', +
  tNewFileName TEXT(100) )

OUT files.$$$
DIR .pGF_Spec
OUT SCREEN

IF CVAL('VERSION') CONTAINS 'Compiler' THEN
  -- Compiler version of DIR output
  LOAD &pGF_Table FROM files.$$$ AS FORMATTED +
    USING tFileDate 26 34 tFileTime 36 42 tDirFlag 14 19 tFileSize 14 23 
tFileName 43 143
ELSE
  -- R:Base version of DIR output
  LOAD &pGF_Table FROM files.$$$ AS FORMATTED +
    USING tFileDate 1 10 tFileTime 13 20 tDirFlag 24 28 tFileSize 29 40 
tFileName 42 142
ENDIF

DELETE FROM &pGF_Table WHERE tFilename IS NULL
DELETE FROM &pGF_Table WHERE tFiledate IS NULL

IF pGF_WithDirs <> 'Y' THEN
  DELETE FROM &pGF_Table WHERE tDirFlag = '<Dir>'
ENDIF

UPDATE &pGF_Table SET tNewFileName = tFileName

SET VAR pGF_Return INT = 0
SELECT COUNT(*) INTO pGF_Return FROM &pGF_Table

RETURN (.pGF_Return)

Reply via email to