Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File infos

0 views
Skip to first unread message

roby

unread,
Apr 23, 2009, 11:09:46 AM4/23/09
to

Hi all.

Using GAWK where can I found informations about a file (i.e.
dimensionlast updated date; and son on ..).

Many thanks

Roby

r.p....@gmail.com

unread,
Apr 23, 2009, 3:56:07 PM4/23/09
to

There are many unix utilities that will report file info...

"ls -l filename" | getline

"file foo" | getline

"stat foo" | getline

"wc foo" | getline

I do think it would be nice to have a couple of these file-stat-
reporting functions built into the language so the scripts would have
more portability and longevity...

Ted Davis

unread,
Apr 23, 2009, 4:01:10 PM4/23/09
to
On Thu, 23 Apr 2009 08:09:46 -0700, roby wrote:

>
> Hi all.
>
> Using GAWK where can I found informations about a file (i.e. dimensionlast
> updated date; and son on ..).
>

You have to ask a utility to give it to you - which one you use and how
you use it depends on the operating system.

You posted from XP, so if we assume that or Linux is the OS of interest,
that the XP time format is 12 hr., and that the file to examine is the
file being processed, then

{
if( NR == 1 ){
Command = "ls -l " FILENAME
while( ( Command | getline S ) > 0 ) {
if( S ~ FILENAME ) {
split( S, A )
print "ls time stamp: " A[6], A[7]
print "ls size: " A[5]
}
}

Command = "dir /tw " FILENAME
while( ( Command | getline S ) > 0 ) {
if( S ~ FILENAME ) {
split( S, A )
print "DIR time stamp: " A[1], A[2], A[3]
print "DIR size: " A[4]
}
}
}

}

One of those routines should do it (tested).
screen dump:

ls time stamp: 2009-04-10 15:16
ls size: 450
DIR time stamp: 04/10/2009 03:16 PM
DIR size: 450
--
T.E.D. (tda...@mst.edu)

roby

unread,
Apr 24, 2009, 1:18:01 PM4/24/09
to

Well this is the solution I'm using.

The question is if exist something internal to GAWK interpreter or
something to use for extending the language.

Many thanks
Roby

Kenny McCormack

unread,
Apr 24, 2009, 1:58:00 PM4/24/09
to
In article <1a2c22e9-fc23-48de...@c12g2000yqc.googlegroups.com>,
roby <ellero...@katamail.com> wrote:
...

>Well this is the solution I'm using.
>
>The question is if exist something internal to GAWK interpreter or
>something to use for extending the language.

As with most things, it depends on exactly what you are looking for (and
what you are willing to settle for). But in GAWK, natively, it is
pretty limited. However, at least under Unix, you can do it using the
"extension function" interface. Details of this upon request.

Note that recent versions claim to be able to do under Windows as well;
I haven't tested that.

0 new messages