Operating System - OpenVMS
1748211 Members
4701 Online
108759 Solutions
New Discussion юеВ

Re: List the latest file

 
SOLVED
Go to solution
Hakan Zanderau ( Anders
Trusted Contributor

Re: List the latest file

Joseph,

The default date & time formats

LIB$DATE_FORMAT_001
LIB$TIME_FORMAT_001

are defined in SYS$STARTUP:VMS$INITIAL-050_LIB.COM

You can define your own date and time format
in table lnm$dt_format_table and make use of it without running LIB$DT_STARTUP.COM

I think I'm right about this, but I'm not 100% sure.

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

Re: List the latest file

As far I tested, only privileged users can do it.
So for average users it is better to rely on definitions done from systartup_vms.
http://www.mpp.mpg.de/~huber
Hakan Zanderau ( Anders
Trusted Contributor

Re: List the latest file

Joseph,

Oppps....forgot about the privileges needed to
define names in lnm$dt_format_table.

The truth is that I have never worked without
privileges on VMS........ and have all privileges enabled by default.

I know...., but that's the way it is ;-)

Hakan
Don't make it worse by guessing.........
Steven Schweda
Honored Contributor

Re: List the latest file

> You can write a DCL command file:

You're right. This came up in the Linux
forum:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1335784

After saying that it would be easy in DCL, I
figured that I ought to try it.

$! 8 May 2009. SMS.
$!
$! Find newest file in (wildcard) P1 specification.
$!
$ prev_file_spec = ""
$ date_max_c = f$cvtime( "17-NOV-1858 00:00:00.00", "COMPARISON")
$ file_spec_max = ""
$!
$ loop_top:
$!
$ file_spec = f$search( p1)
$!
$! Quit if out of files, or (non-wildcard) look-up repeats.
$!
$ if ((file_spec .eqs. "") .or. -
(file_spec .eqs. prev_file_spec)) then goto loop_end
$!
$ prev_file_spec = file_spec
$!
$! Get file revision date, and convert it to "COMPARISON" format.
$!
$ file_date = f$file_attributes( file_spec, "RDT")
$ file_date_c = f$cvtime( file_date, "COMPARISON")
$!
$! Save the information for a new newest file.
$!
$ if (file_date_c .gts. date_max_c)
$ then
$ file_spec_max = file_spec
$ date_max_c = file_date_c
$ endif
$!
$ goto loop_top
$ loop_end:
$!
$! If anything was found, display its information.
$!
$ if (file_spec_max .nes. "")
$ then
$ write sys$output file_spec_max
$ write sys$output date_max_c
$ endif
$!

Easy enough, I reckon.
Joseph Huber_1
Honored Contributor

Re: List the latest file

And here (without own programming), let the fine GNV do the work:-)

$ bash -c "ls -lt"
http://www.mpp.mpg.de/~huber
Steven Schweda
Honored Contributor

Re: List the latest file

> $ bash -c "ls -lt"

That gives me more than "the [...] file".
Or did you mean this?:

$ bash -c "ls -lt | head -2 | tail -1"

The DCL method runs faster, and easily does
recursive descent into subdirectories
("[...]"), which is tougher to do with a
UNIX-like method.

As usual, many things are possible.
Joseph Huber_1
Honored Contributor

Re: List the latest file

>>That gives me more than "the [...] file".
>>Or did you mean this?:
>>$ bash -c "ls -lt | head -2 | tail -1"

Yea right, thats exactly to get the one newest file, as Your DCL command file is doing.

I was just comparing the bash one liner to my dir_by_date.com .
http://www.mpp.mpg.de/~huber