This is where BASIC really shines, is with string handling. I needed to build some cleanup routines, for example a utility to delete any files in the _PH_ directory that are over 2 days old. Although you can create a DIR pointer where each filename in the directory appears as the record key, you need to go to the OS level to get the date / time stamp. I built a subroutine that can provide the calling program a list (array) of filenames and their associated date stamp, allowing the calling program to look through the list and take action based on the date. Note that AIX may have a different format to the output and the parsing code may need to be tweaked. This was written in Unidata, but I believe it should work in Universe as well. There may be more elegant solutions, but this took 10 minutes to create and does the job :-)
SUBROUTINE OSDIR.INFO(DIRNAME,FILELIST)
* Unidata file date subroutine * Rocket Software * msapp * 12/10/2019
* Returns an associated list - FILELIST<1,nn> = file name and FILELIST<2,nn> = internal date
* For FILE cleanup, you can compare the date to your threshold to determine if the file should be deleted
* Use with caution !!! Note: Used against Linux OS, other unix variants could need different parsing
*
BEGIN CASE
CASE DIRNAME[1,2] = "./" ;* one level down
* OK, no action needed
CASE DIRNAME[1,1] = "/" ;* Assumes full path
* OK, no action needed
CASE DIRNAME[1,1] = "." ;* Second char is not '/' so add it in
DIRNAME = "./":DIRNAME[2,LEN(DIRNAME)]
CASE 1
DIRNAME = "./":DIRNAME
END CASE
* Get list of files with date stamp at OS level
PCMD = "ls -l --time-style=long-iso ":DIRNAME
PCPERFORM PCMD CAPTURING PRISONERS
*
FLIST = TRIM(PRISONERS)
LNS = DCOUNT(FLIST,@FM)
TD = DATE()
THIS.YR = OCONV(TD,"DY")
*
CNTR = 0
FILELIST = ""
*
FOR X = 1 TO LNS
THIS.LINE = FLIST<X>
THIS.DATE = FIELD(THIS.LINE," ",6)
* Current year will not contain year in the date stamp
MM = FIELD(THIS.DATE,"-",3)
DD = FIELD(THIS.DATE,"-",2)
YY = FIELD(THIS.DATE,"-",1)
IF INDEX(YY,":",1) > 0 THEN YY = THIS.YR
ODATE = DD : " " : MM : " " : YY
FNAME = FIELD(THIS.LINE," ",8)
IF FNAME[1,1] = "." THEN CONTINUE
IF FNAME[1,1] = " " THEN CONTINUE
IF FNAME = "" THEN CONTINUE
*
IDATE = ICONV(ODATE,"D")
CNTR +=1
FILELIST<1,CNTR> = FNAME
FILELIST<2,CNTR> = IDATE
NEXT X
*
RETURN
You can test this by creating a test program:
CRT "* Get file list *"
CRT "Enter DIR name: ":
INPUT FNAME
FILELIST = ""
CALL OSDIR.INFO(DIRNAME,FILELIST)
LCNT = DCOUNT(FILELIST,@AM)
FOR X = 1 TO LCNT
PRINT FIELDLIST<X,1> : " - " : OCONV(FILELIST<X,2>,"D4/")
NEXT X