ls -l命令和stat的结果不一致

jiangfeng999 jiangfeng999 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在linux下发现一个很奇怪的现象,我把几个7月的文件夹(以及文件夹下的文件和目录)tar到一个新的目录下。用ls -l命令看到的文件时间还是7月份的时间。然后我用以下代码去显示解压后的文件的时间,发现用程序显示出的时间却是当前解压缩的时间。
代码如下:
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <string.h>
int main()
{
char strFilename[200]="xxxxxxxxxxxxxxxxxxxx";
struct dirent* pdir;
char strFile[200];
DIR* dir;
time_t tDirCreate;
struct stat buf;
dir = opendir(strFilename);
while(( pdir = readdir(dir)) != NULL)
{
if ((strcmp(pdir->d_name,".") != 0) && (strcmp(pdir->d_name,"..") != 0))
{
memset(strFile,'\0',sizeof(strFile));
strcpy(strFile,strFilename);
strcat(strFile,"/");
strcat(strFile,pdir->d_name);
sprintf(strFile,"%s%s",strFile,"/");
memset(&buf,'\0',sizeof(buf));
stat(strFile,&buf);
tDirCreate=buf.st_ctime;
printf("\niDelFile:%s\n %s %s %s\n",strFile,ctime(&tDirCreate),
ctime(&buf.st_atime),ctime(&buf.st_mtime));
}
}
closedir(dir);
exit(1);
}


...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
jiangfeng999
Linux/Unix社区 23,224 成员 74,535 内容