[완료] stat좀 봐주세요...
글쓴이: kaje0105 / 작성시간: 수, 2007/11/28 - 4:58오후
...
DIR *dir;
struct dirent *dent;
struct stat statbuf;
dir = opendir(DIRECTORY)
while(dent = readdir(dir))
{
if(stat(dent -> d_name, &statbuf) == -1)
printf("stat error\n");
if(S_ISDIR(statbuf.st_mode) == 0)
printf("%s\n", dent -> d_name);
}
...
directory를 read 해서 directory안의 file만 골라서 print하는
간단한 program 입니다. stat error message만 자꾸 나오네요..
혹시나 해서 전부 주석처리 하고 printf("%s\n", dent -> d_name);
만 남겨 놓으니까 directory안의 내용이 잘 출력은 됩니다..
사용법엔 이상이 없는것 같은데 왜 자꾸 error가 나는지 모르겠네요..
Forums:
dent->d_name 이..
현재 경로에 없는 파일이기 때문일겁니다.
DIRECTORY/(dent->d_name) 와 같이 경로를 만들어서 stat() 을 호출해보세요.
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
감사합니다.. full path
감사합니다.. full path name을 주어야 하는군요..^^
char rename[255];
sprintf(rename, "%s%s", DIRECTORY, dent -> d_name)
stat(rename, &statbuf)
이런식으로 만들어서 하니까 잘 동작합니다
저 같은 초보분들을 위해서...
홧팅~
댓글 달기