Using GAWK where can I found informations about a file (i.e.
dimensionlast updated date; and son on ..).
Many thanks
Roby
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...
>
> 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)
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
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.