Computing.Net > Forums > OpenVMS > dir /date

dir /date

Reply to Message Icon

Original Message
Name: Jim Laragy
Date: August 31, 2001 at 08:28:18 Pacific
Subject: dir /date
Comment:

How can I sort a directory listing in VMS by date like the ls -t command does in Unix.
Thanks.
Jim Laragy


Report Offensive Message For Removal


Response Number 1
Name: Klaus
Date: September 4, 2001 at 05:11:47 Pacific
Subject: dir /date
Reply: (edit)

try to create an output file with:

dir/dat/width=(filename=30)/col=1/out=out.lis

and then sort by the following command (you have to count the positions of the date information and maybe you want to sort by the year first, then month and day)

$ SORT/KEY=(POS:16,SIZ:3)/KEY(POS:1,SIZ:11) -
_$ /KEY=(POS:40,SIZ:2,DESC) out.lis out_sort.LIS

This SORT command identifies three key fields. The input file, out, is first sorted by the key beginning in position 16, then by the key beginning in position 1, and finally by the key beginning in position 40. The third key used sorts in descending order.

As you can sea, there is no simple way just using a command, but it works.

Hope this helps

Klaus


Report Offensive Follow Up For Removal

Response Number 2
Name: anon
Date: September 13, 2001 at 03:43:28 Pacific
Subject: dir /date
Reply: (edit)

There are two issues here. One is trying to get rid of the pesky temporary file, the other is to sort a date field containing the month names. The latter can be done with a SORT specification file. Here is an example which assumes /WIDTH=(FILENAME:40). Adjust the POSITION values for different widths:


We'll call it DIRDATE.SPEC and assume it's in SYS$LOGIN.

/FIELD=(NAME:YEAR, POSITION:50, SIZE:4, CHAR)
/FIELD=(NAME:MONTH, POSITION:47, SIZE:2, CHAR)
/FIELD=(NAME:DAY, POSITION:43, SIZE:2, CHAR)
/FIELD=(NAME:TIME, POSITION=55, SIZE:11,CHAR)
/FIELD=(NAME:RECORD, POSITION:1, SIZE:80, CHAR)
/KEY=YEAR
/KEY=MONTH
/KEY=DAY
/KEY=TIME
/DATA=RECORD
/COLLATING_SEQUENCE=(SEQUENCE=("AN","EB","AR","PR","AY","UN",
"UL","UG","EP","CT","OV","EC","0"-"9"),
MODIFICATION=("'"="19"),FOLD)

-- end of DIRDATE.SPEC

Now the problem of the temporary file. Since V7.1, OpenVMS has had a pipe command, a bit like Unix (but not quite as slick). So, we can now do the whole thing in one command:

$ PIPE DIRECTORY/DATE -
/WIDTH=(FILENAME:40)/COLUMN=1 | -
SORT/SPECIFICATION=SYS$LOGIN:DIRDATE.SPEC -
SYS$PIPE: SYS$OUTPUT:

The result will be a directory sorted by date (except that the trailer line will end up at the top of the listing).


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: dir /date

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge