Below is an example program submitted by Hakan. He developed this program to automatically download SEC (Security and Exchange Commission) index files of company filings from the SEC FTP site.

This program assumes that PKZIP.EXE and the freeware utility WGET.EXE are installed on your system.

The following version is "as submitted" by Hakan. There is a slight inconvenience in this version because you'll have to go through it, line by line, and customize it for your system's file directory structure. Our programming "style" specifies all system dependant items as constants and these constants are defined a the top of the program. This "portable" version is provided at: Stock_index_a.html.


/*
 Name:  SECIDX.CMD

 Description:Retrieve SEC archived and current index files beginning a given year

 Author:  HG 5/21/01

 Comment: None

 Usage:  Run in OS/2 CMD session

 Arguments: None

 Output:  None

 Bugs:  None

 Fixes:  None
*/

/* beginning year */
beginningYear = 2000

/* directories */
localDir = "F:\SEC\"

/* server information */
hostURL = "ftp://ftp.sec.gov"
hostDir = "/edgar/"

/* install REXX function library */
rc = RxFuncAdd( "SysSleep", "RexxUtil", "SysSleep" )
say "Return code 1:" rc

/* get today's  date in standard format, i.e., YYYYMMDD */
today = date( s )

/* retrieve year and month from date */
currentYear = left( today, 4 )
currentMonth = substr( today, 5, 2 )

/* download archived index files */
do year = beginningYear to currentYear by 1

 /* create directory name */
 dir = hostDir || "full-index/" || year || "/"

 /* mirror index files and remove one level of directories */
 /* wget options: use recursion, file mask, timestamp, no DNS search, and remove one level of directories */
 fileMask = "master.zip"
 "F:\wget\os2\wget -r -A " || fileMask || " -N -nH --cut-dirs=1" hostURL || dir
end

/* calculate range of daily files needed */
if ( currentMonth <= 3 ) then do
 beginningMonth = 1
end
else
if ( currentMonth <= 6 ) then do
 beginningMonth = 4
end
else
if ( currentMonth <= 9 ) then do
 beginningMonth = 7
end
else
if ( currentMonth <= 12 ) then do
 beginningMonth = 10
end

/* mirror daily index files and remove one level of directories */
/* wget options: use one level recursion, file mask, timestamp, no DNS search, and remove one level of directories */
dir = hostDir || "daily-index/"
do month = beginningMonth to currentMonth by 1
 month = right( month, 2, "0" )
 fileMask = "master." || currentYear || month || "*.idx"
 "F:\wget\os2\wget -r -l 1 -A " || fileMask || " -N -nH --cut-dirs=1" hostURL || dir
end

/* search directory for index files */
rc = SysFileTree( localDir || "*.zip", documents, "FS" )
if ( rc > 0 ) then do
 say "Building tree with index files failed..." rc
end

/* report number of matching index files */
say documents.0 || " index files found"

/* loop through each file and unpack data if it needs to be updated */
if ( documents.0 > 0 ) then do
 do i = 1 to documents.0
  parse var documents.i date time size flags fullName
  say "Unpacking file" i "of" documents.0 ":" fullName

  /* extract directory */
  temp = filespec( "p", fullName )
  dir = left( temp, length( temp ) - 1 )

  /* change directory */
  rc = directory( dir )

  /* update file */
  "F:\OS2Utils\PKZipOS2\PKZip /extract=upd " || fullName
 end
end

/* exit program */
exit

Rexx Group Charter
Lesson 1 | Lesson 2 | Lesson 3 | Lesson 4
Exercises 1 | Exercises 2 | Exercises 3
Answers to exercises
Exercises 1
Example code
Stock Market | Stock Market_a


About these pages
Content updated: 07-09-2005 10:21am

Page building by: PPWizard Content updated
07-09-2005 10:21am
Valid HTML 4.01!Valid CSS!