리눅스 시스템에서 임의의 파일이 파일인지 디렉터리인지 구별하고 싶은데 방법을 모르겠습니다..
즉
/usr/locarl/some
여기서 some이 디렉터리인지 파일인지 알고 싶은데요...방법이 있을까요? 구별해 주는 시스템 함수같은게 없는지요?
$ man 2 fstat
<어떠한 역경에도 굴하지 않는 '하양 지훈'>
#include <com.h> <C2H5OH.h> <woman.h> do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);
APU 책 부록에 있는 프로그램에 있는 내용입니다.
#include <sys/types.h> #include <sys/stat.h> int main(int argc, char *argv[]) { int i; struct stat buf; char *ptr; for (i = 1; i < argc; i++) { printf("%s: ", argv[i]); if (lstat(argv[i], &buf) < 0) { err_ret("lstat error"); continue; } if (S_ISREG(buf.st_mode)) ptr = "regular"; else if (S_ISDIR(buf.st_mode)) ptr = "directory"; else if (S_ISCHR(buf.st_mode)) ptr = "character special"; else if (S_ISBLK(buf.st_mode)) ptr = "block special"; else if (S_ISFIFO(buf.st_mode)) ptr = "fifo"; #ifdef S_ISLNK else if (S_ISLNK(buf.st_mode)) ptr = "symbolic link"; #endif #ifdef S_ISSOCK else if (S_ISSOCK(buf.st_mode)) ptr = "socket"; #endif else ptr = "** unknown mode **"; printf("%s\n", ptr); } exit(0); }
감사합니다..참고 하겠습니다.
man 2 stat man 2 fstat
리턴후 struct stat 구조체 값에 채워지는 멤버 변수 중 st_mode가 파일타입을 알려줍니다. (퍼미션도 갖고 있습니다)
Written By the Black Knight of Destruction
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
[code:1]$ man 2 fstat[/code:1] <어
$ man 2 fstat
<어떠한 역경에도 굴하지 않는 '하양 지훈'>
#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);
C 언어에서 파일의 속성 알아보기
APU 책 부록에 있는 프로그램에 있는 내용입니다.
감사^^
감사합니다..참고 하겠습니다.
man 2 statman 2 fstat리턴후 struct st
man 2 stat
man 2 fstat
리턴후 struct stat 구조체 값에 채워지는 멤버 변수 중 st_mode가
파일타입을 알려줍니다. (퍼미션도 갖고 있습니다)
Written By the Black Knight of Destruction
댓글 달기