Operating System - OpenVMS
1752717 Members
5738 Online
108789 Solutions
New Discussion юеВ

Re: List the latest file

 
SOLVED
Go to solution
Per Arvidsson
New Member

List the latest file

In DCL how can I get the latest created file on a directory?
16 REPLIES 16
Joseph Huber_1
Honored Contributor
Solution

Re: List the latest file

You can write a DCL command file:

lastfile=""
last="17-NOV-1858"
last=f$cvtim(last,"COMPARISON")

Loop with file=f$search("*.*") over the directory,
get the creation date cdt=f$file(file,"CDT")
convert the date to comparison cdt=f$cvtim(cdt,"COMPARISON")
Compare to the last time saved
Set last to cdt if cdt .ges. last
Set lastfile to file in this case
Continue loop.

Or search on the VMS freeware disks for the program DIRBYDATE: it does not give You just the latest, but a directory listing with the latest first or last in the list.
http://www.mpp.mpg.de/~huber
Hakan Zanderau ( Anders
Trusted Contributor

Re: List the latest file

Per,

What are you trying to do ?
We need more detailed information.

Hakan

Ps. Jobbade tidigare p├Г┬е VMS-supporten hos Digital/Compaq/HP. Ds.
Don't make it worse by guessing.........
Kris Clippeleyr
Honored Contributor

Re: List the latest file

Per,

You could use QDSB, downloadable from
http://www.quadratrix.be/qdsb.html

Example:
$ QDSB/SORTED=DATE_C=ORDER=DESC

Kris (aka Qkcl)

I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Per Arvidsson
New Member

Re: List the latest file

Thank you all, Wow!
What a response
Per Arvidsson
New Member

Re: List the latest file

I tried to pipe dir and sort but didnt succeed. These answers will do
Joseph Huber_1
Honored Contributor

Re: List the latest file

I think Kris's program is the most excellent doing a sorted directory anyway.

>> tried to pipe dir and sort but didnt succeed.

Because the default date format is not ISO or VMS "comparison": one has to switch date-format before the directory command, and has to fix the output fields with the /width qualifier, then one can pipe the output through sort.

I did this for the file size (because it's simpler :-), see
http://wwwvms.mppmu.mpg.de/util_root/com/dir_by_size.com

http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: List the latest file

A quick hack in DCL piping directory output into sort is at
http://wwwvms.mppmu.mpg.de/util_root/com/dir_by_date.com

but it will break the correct order and display whenever a dir-/file-specification exceeds the filename field width (80 in my example).

A slower DCL version using f$search loop is
http://wwwvms.mppmu.mpg.de/util_root/com/dir_by_date2.com

http://www.mpp.mpg.de/~huber
Hakan Zanderau ( Anders
Trusted Contributor

Re: List the latest file

$ DEFINE/EXEC/TAB=LNM$DT_FORMAT_TABLE LIB$DATE_FORMAT_COMPARISON "!Y4-!MN0-!D0"
$ DEFINE LIB$DT_FORMAT LIB$DATE_FORMAT_COMPARISON,LIB_TIME_FORMAT_001
$ pipe (dir/date/wid=file=40 | search sys$input ";" | sort/key=(pos:43,siz:22,desc) s
ys$input sys$output)

Hakan
Don't make it worse by guessing.........
Joseph Huber_1
Honored Contributor

Re: List the latest file

BTW, the LIB$DT_FORMAT feature only works if
@sys$startup:lib$dt_startup has been executed (best insert this in systartup_vms ).
http://www.mpp.mpg.de/~huber