[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: Reading Multiple Files and Renaming Input File
- Subject: Re: Reading Multiple Files and Renaming Input File
- From: Krisjanis Gale <Krisjanis.Gale@NY.FRB.ORG>
- Date: Thu, 22 Jul 1999 10:07:40 -0400
>>> Aaron Chang <Aaron.Chang@ANU.EDU.AU> Wednesday, July 21, 1999 7:03:30 PM >>>
> Hi all
hello there.
->
I've written an SQR to read information from a flat file. However, the
input file name will change daily - based on a prefix of the program name
and a time stamp (ie. NAME_CCYYMMDD_HHMMSS.dat). In addition,
after reading the input files, the SQR program is required to rename the suffix
of the input file from 'dat' to 'pro'.
--
you can rename a file using SQR's rename() procedure.
like so:
let #status = rename($filename,$newfilename)
if #status = 0
show 'file ' $filename ' renamed to ' $newfilename
else
show 'error renaming ' $filename ' to ' $newfilename ', status = ' #status
end-if
->
Does anyone know of a way to loop the SQR until it has read all files prefixed by
"NAME_" and suffixed by 'dat'. Also, a way to rename the input file dynamically
from the SQR program (ie. rename the suffix of the input file from 'dat' to 'pro'). I've
been told that there is a way to execute DOS command from SQR to rename the
input file but I'm unsure of the syntax.
--
i would do this:
1) use SQR's CALL SYSTEM command to get a directory listing of your .dat files.
like so:
let $dir = 'dir *.dat /-p /on /b > datlist.dir'
! the /-p is to shut off pausing (if it is set in the environment variable DIRCMD)
! the /on sorts the listing by name
! the /b switches to "brief" listing mode (no file details, just the filenames)
Call System Using $dir #status
what you get is, essentially, a sorted flatfile of your .dat files,
in this format:
111111.dat
222222.dat
....
2) open this directory listing using SQR's OPEN command
like so:
open 'datlist.dir' as 1 for-reading record=80:Vary #status
! do #status check here, if necessary; 0 if successful, -1 if not
3) READ the file, looping until EOF (end-of-file) or error is encountered
while #end-file=0 or #status<>0
! read until EOF, or #status returned by READ is not 0
read 1 into $filename #status
if #status=0
! do your logic with the $filename here
end-if
end-while
hope that gets you started.
(kris)janis p. gale
hrsd - federal reserve bank of new york
x8163