- 论坛徽章:
- 0
|
改成下面这样就可以了:
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
void do_ls(char* pathname)
{
struct stat sbuf;
struct dirent* pdirent;
DIR* pdir;
char ct[30];
if ((pdir = opendir(pathname)) != NULL)
{
chdir(pathname);
printf("-----%s-----\n", pathname);
while ((pdirent = readdir(pdir)) != NULL)
{
printf("%s\t", pdirent->d_name);
if (stat(pdirent->d_name, &sbuf) != -1)
{
strftime(ct, 30, "%Y%m%d%H%M%S", localtime(&sbuf.st_ctime));
printf("%s\t%d\t%d\n", ct, sbuf.st_size, sbuf.st_uid);
}
}
printf("-------------\n");
printf("\n");
closedir(pdir);
}
else
perror(pathname);
}
|
为什么得到的日期字符串必须放在前面才能打印呢?
比较一下:
strftime(ct, 30, "%Y%m%d%H%M%S", localtime(&sbuf.st_ctime));
printf("%d\t%s\t%d\n", sbuf.st_size, ct, sbuf.st_uid);
strftime(ct, 30, "%Y%m%d%H%M%S", localtime(&sbuf.st_ctime));
printf("%s\t%d\t%d\n", ct, sbuf.st_size, sbuf.st_uid);
[ 本帖最后由 happy1123 于 2007-8-27 21:28 编辑 ] |
|