Mike,
I neglected to note that the procedure assumes you are working with 7.6 12/12 build or newer, as that is about the time that the format of the DIRectory display changed. You should note that the code retains the setting of SHORTNAME, a setting that was introduced along with the new format. If you are working with an older version, I can provide a table structure and the LOAD command to work with that. It should be a drop-in for this procedure. Of course, had I anticipated the request, I might have included a version check along with the SHORTNAME setting and created the appropriate table. In other words, with a little work this could become generic. 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 Emmitt Dove Sent: Sunday, January 04, 2009 10:40 PM To: RBASE-L Mailing List Subject: [RBASE-L] - RE: Best way to import file names into a table Mike, Here is a stored procedure to do just what you ask. The comments at the top of the file illustrate the usage, and how to PUT the procedure. What you do in your code is set up the file mask you wish to filter, including the full path or the relative path, then CALL the procedure. It will return the count of the number of files in the table “filenams.” The table is a temporary table, but your calling code must be responsible for DROPping it when finished. Look in the code for the CREATE TEMPORARY TABLE command to see the structure. You’ll end up with a row on the table for each file that meets the mask you submit, with the proper date, time and file size information available. ---=========================================================== --- ftable.prc stored procedure to create and load table filenams using --- the specified file mask 12/12/2008 Emmitt Dove --- usage: SET VAR vfcount INTEGER = (CALL ftable(.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 ftable.prc AS ftable fmask TEXT (200) RETURN INTEGER + --- COMMENT 'Load table filenams 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 filenams SET ERROR MESSAGE 2038 ON CREATE TEMPORARY TABLE filenams (filedate DATE,filetime TIME,ampm TEXT (2),+ filesize INTEGER,longfn TEXT (60)) -- load the table LOAD filenams + FROM &ftempfn + AS FORMATTED USING filedate 1 8,filetime 13 17,ampm 19 20,+ filesize 28 40,longfn 42 101 -- 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 filenams + WHERE longfn IN ('.','..','bytes','bytes free') DELETE ROWS + FROM filenams + WHERE longfn IS NULL OR + longfn = ' ' DELETE ROWS + FROM filenams + WHERE filesize IS NULL -- fix the time values UPDATE filenams + 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 filenams 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, MD Sent: Sunday, January 04, 2009 7:58 PM To: RBASE-L Mailing List Subject: [RBASE-L] - Best way to import file names into a table Hi all, I want to be able to import all the filenames in a folder into a column in a table. I also want to be able to import the entire pathname\filename.ext into a different column. Is there an easy way to do that or do I need do things like.... output temp.txt dir output screen load tablename from temp.txt etc.... TIA! Mike

