69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <assert.h>
static void TraveDir (char *DirName)
{
DIR *pDir;
struct dirent *DirHand;
struct stat *StaBuf;
pDir = opendir(DirName);
char ChildDir[256];
strcpy(ChildDir,DirName);
assert(pDir != NULL);
while( (DirHand = readdir(pDir)) != NULL )
{
if(DirHand->d_type == 4)
{
if( strcmp(DirHand->d_name,".") == 0 || strcmp(DirHand->d_name,"..") == 0 )
{
continue;
}
sprintf(ChildDir,"%s/%s",DirName,DirHand->d_name);
TraveDir(ChildDir);
}
else if(DirHand->d_type == 8)
{
char FileName[256];
sprintf(FileName,"%s/%s",ChildDir,DirHand->d_name);
stat(FileName,StaBuf);
printf("%s %ld\n",FileName,StaBuf->st_atime);
}
}
closedir(pDir);
}
int main(void)
{
char *path = "/tmp";
TraveDir(path);
return 1;
}