Mike,
You asked “Is there a better way to load a list of filename from a folder into
a table?”
Here is a stored procedure that will take a file mask as an argument and return
a table with the matching files in the specified location. It requires that
you know what you’re looking for and where to find it, so it differs from the
rbl approach as there is no user interface. It handles up to 128-character
filenames, and preserves your database’s setting for SHORTNAME. You supply the
mask, and the SP returns the count of matching files plus the temporary table
holding the results. The calling code is responsible for dropping the temp
table when it is finished with it. All the variables in the SP begin with ‘f’
and are cleared at the end; if your calling code wants to use variables that
begin with ‘f’, you’ll have to do something about that. The SP will not work
if the R:BASE version doesn’t support the SHORTNAME setting and will return 0.
Each entry on the table will contain the file name, date, time in 24-hour
format, and file size.
--- ft128.prc based on file mask returns a temp table with matching
--- files and the count of those files 9/29/2009 Emmitt Dove
---
--- usage: SET VAR vfcount INTEGER = (CALL ft128(.vfmask))
---
--- where vfmask is the filename mask to use. vfmask may include the
--- full path to the files, otherwise the current folder is assumed
--- to create the stored procedure do this:
---
--- PUT ft128.prc AS ft128 fmask TEXT (200) RETURN INTEGER +
--- COMMENT 'Load table filen128 from specified mask'
---
--- filename mask will be in variable fmask
--- returns a count of the number of files in the temporary table
--- note: the calling code is responsible for dropping the temporary table
-- want to retain current setting for SHORTNAME
SET VAR fshort = (CVAL('shortname'))
IF fshort IS NULL THEN
-- parameter not recognized by this version of R:BASE
RETURN 0
ENDIF
IF fshort = 'ON' THEN
SET SHORTNAME OFF
ENDIF
-- set up the temporary filename to hold the directory listing
SET VAR fxfn = (FILENAME(0))
SET VAR ffnlen = (SLEN(.fxfn))
SET VAR ftempfn = (SGET(.fxfn,8,(.ffnlen - 11))+CTXT('.lst'))
-- delete the file R:BASE created
DELETE &fxfn
-- get the listing
OUTPUT &ftempfn
SET VAR fcmd = (CTXT('DIR')&CTXT(.fmask))
&fcmd
OUTPUT SCREEN
-- create the table
SET ERROR MESSAGE 2038 OFF
DROP TABLE filen128
SET ERROR MESSAGE 2038 ON
CREATE TEMPORARY TABLE filen128 (filedate DATE,filetime TIME,ampm TEXT (2),+
filesize INTEGER,longfn128 TEXT (128))
-- load the table
LOAD filen128 +
FROM &ftempfn +
AS FORMATTED USING filedate 1 8,filetime 13 17,ampm 19 20,+
filesize 28 40,longfn128 42 169
-- delete the temp file holding the listing
DELETE &ftempfn
-- restore SHORTNAME setting
SET VAR fcmd = (CTXT('SET SHORTNAME')&CTXT(.fshort))
&fcmd
-- remove irrelevant rows
DELETE ROWS +
FROM filen128 +
WHERE longfn128 IN ('.','..','bytes','bytes free') OR +
longfn128 IS NULL OR +
longfn128 = ' ' OR +
filesize IS NULL
-- fix the time values
UPDATE filen128 +
SET filetime = (ADDHR(filetime,12)) +
WHERE ampm = 'PM' AND +
filetime < 12:00:00
-- get the number of rows
SET VAR fcount INTEGER
SELECT COUNT(*) +
INTO fcount INDIC fi1 +
FROM filen128
IF fcount IS NULL THEN
SET VAR fcount = 0
ENDIF
SET VAR vfcount INTEGER = .fcount
CLEAR VAR f%
RETURN .vfcount
Emmitt Dove
Manager, Converting Applications Development
Evergreen Packaging, Inc.
[email protected]
(203) 214-5683 m
(203) 643-8022 o
(203) 643-8086 f
[email protected]
From: [email protected] [mailto:[email protected]] On Behalf Of Michael J.
Sinclair
Sent: Sunday, February 21, 2010 18:02
To: RBASE-L Mailing List
Subject: [RBASE-L] - Why won't this work during trace, but does work during RUN?
Hi All,
I am using Rbase 7.6, latest build.
I am trying to load a list of file names into a table. The method I am using
seems to work just fine when I run the command, but fails (nothing loads into
the table) while I am doing a trace. The program is run from within an EEP.
Here is my code....
ERASE dir.txt
OUTPUT dir.txt
DIR .vfromspec
OUTPUT SCREEN
DELETE FROM asciitxt2
LOAD asciitxt2 FROM dir.txt AS FORMATTED USING textdata 1 80
EDIT ALL FROM asciitxt2
The contents of dir.txt is as follows....
Volume in drive g is 320GB
Volume Serial Number is 8464-4871
Directory of g:\docs\1913\labs\
02/20/2010 10:43 PM <DIR> .
02/20/2010 10:43 PM <DIR> ..
11/28/2009 03:02 PM 9,618 labs_1913_0001.pdf
1 File(s) 9,618 bytes
2 Dir(s) 28,672,167,936 bytes free
Why won't this work for me during a trace? Is there a better way to load a list
of filename from a folder into a table?
Mike