|
From: Reid T. <rei...@at...> - 2005-11-30 15:42:57
|
Jason Benjamin wrote:
>In order to convert time_create I probably must use
>time_t or something. How do I do the actual
>conversion though?
>
>//************************
>#include <io.h>
>#include <stdio.h>
>#include <string.h>
>int i = 0;
>int m=0;
>char filelist[100][100];
>
>struct _finddata_t fd;
>
>
>int main() {
>long fh = _findfirst("*.*", &fd);
>
>
>if (fh != -1) {
>
>
> do {
> if (fd.attrib & _A_SUBDIR);
>
>
> else sprintf(filelist[i++], fd.time_create);
>
> }
> while (_findnext(fh, &fd) == 0);
>
>m=i;
>for (i=0; i < m; i++) printf("%s\n", filelist[i]);
>system("pause");
>_findclose(fh);
>}
>return 0;
>}
>
>
See comment 3.1 at the bottom. (
http://www.faqs.org/faqs/unix-faq/faq/part3/section-1.html)
modified from
http://www.unix-ag.uni-siegen.de/docs/unix/unix.html#SEC168 ( should
provide the answer you are requesting).
/********************************************************************/
/* */
/* Reading directories and `statting' files */
/* */
/* modified from
http://www.unix-ag.uni-siegen.de/docs/unix/unix.html#SEC168 */
/********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#define DIRNAME "."
#define bufsize 1024
/********************************************************************/
int main()
{
DIR *dirh;
struct dirent *dirp;
struct stat statbuf;
char pathname[bufsize];
char *linkname[bufsize];
if ((dirh = opendir(DIRNAME)) == NULL)
{
perror("opendir");
exit(1);
}
for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh))
{
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name)
== 0)
{
continue;
}
if (strcmp("lost+found", dirp->d_name) == 0)
{
continue;
}
sprintf(pathname, "%s/%s", DIRNAME, dirp->d_name);
if (lstat(pathname, &statbuf) == -1) /* see man stat */
{
perror("stat");
continue;
}
if (S_ISREG(statbuf.st_mode))
{
printf("%s is a regular file\n", pathname);
};
if (S_ISDIR(statbuf.st_mode))
{
printf("%s is a directory\n", pathname);
}
if (S_ISLNK(statbuf.st_mode))
{
bzero(linkname, bufsize); /* clear string */
readlink(pathname, linkname, bufsize);
printf("%s is a link to %s\n", pathname, linkname);
}
printf("The mode of %s is %o\n\n", pathname, statbuf.st_mode &
07777);
printf("The c_time is %ld\n\n", statbuf.st_ctime);
printf("This is local time of %s\n\n",
asctime(localtime(&statbuf.st_ctime)));
}
closedir(dirh);
}
3.1) How do I find the creation time of a file?
You can't - it isn't stored anywhere. Files have a last-modified
time (shown by "ls -l"), a last-accessed time (shown by "ls -lu")
and an inode change time (shown by "ls -lc"). The latter is often
referred to as the "creation time" - even in some man pages -
but that's wrong; it's also set by such operations as mv, ln,
chmod, chown and chgrp.
The man page for "stat(2)" discusses this.
|