Date: Thu, 26 Apr 2001 14:20:49 -0400
Reply-To: Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Organization: Dartmouth College
Subject: Re: Capturing File Data in UNIX
There must be a better way of getting file system information in SAS then
parsing the output of ls, anybody have any ideas? Are there SCL functions
that many of us might not know about?
The only thing that comes to mind is writing a program that calls one of the
Unix stat functions (e.g. stat, lstat) and then calling that from a pipe --
but am I missing some easier Unix command that will whip this out?
To simplify the filename and program down to something like this:
filename cdate pipe "./cDate test.csv";
data _null_;
infile cdate missover;
input fdate datetime.;
put "The file i-node was last changed: " fdate datetime.;
run;
I wrote a quick implementation of a program called cDate that just calls
lstat and returns the last i-node change date in SAS datetime format.
(Incidentally, the O'Reilly book says, "Note that, contrary to popular
belief (and contrary to many UNIX programming books), this field does not
represent the time the file was created. File creation time is not recorded
anywhere on the filesystem.")
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
int
main(int argc, char **argv)
{
struct stat st;
char* fileName;
char time[BUFSIZ];
if (argc != 2) {
(void)fprintf(stderr, "Usage: %s filename\n", argv[0]);
return(EXIT_FAILURE);
}
fileName = argv[1];
if (lstat(fileName, &st) < 0) {
(void)fprintf(stderr, "Unable to lstat %s.\n", fileName);
return(EXIT_FAILURE);
}
(void)cftime(time, "%d%b%Y:%T", &st.st_ctime);
(void)fprintf(stdout, "%s\n", time);
return(EXIT_SUCCESS);
}
I'm looking forward to any responses or suggestions that folks might have.
--
Bob Burnham
robert.a.burnham@dartmouth.edu
http://www.dartmouth.edu/~bburnham