lstat를 이용해서 directory scan 및 file 찾기
현재 directory에 CLI_aaa, CLI_bbb, CLI_ccc file3개가 있고
만들어진 날짜가 다를때 가장 오래된 file을 찾아서 그파일을
삭제하는 코드를 짜려고 합니다. 더 어떻게 해야하는지
고수님좀 도와주세요... ㅡ.ㅡ
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
int count_CLI_log(char *logdir_name,char *loguser_name)
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;
int CLI_logcnt = 0;
int i;
if((dp=opendir(logdir_name)) == NULL)
{
printf("error: opendir fail\n");
return(-1);
}
while((entry=readdir(dp)) != NULL)
{
if(strstr(entry->d_name, loguser_name))
{
lstat(entry->d_name,&statbuf);
printf("%s %d\n",entry->d_name,statbuf.st_mtime);
CLI_logcnt++;
}
}
closedir(dp);
return(CLI_logcnt);
}
int main()
{
int log_cnt,number;
log_cnt=count_CLI_log(".","CLI_");
printf("log_cnt %d\n",log_cnt);
}
댓글 달기