unix c 練習程式

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

int main(){
struct stat sb;
int ret;

ret = stat("./debug", &sb);
if (ret){
perror("stat");
return 1;
}

if (S_ISDIR(sb.st_mode)) {
puts("debug is a dir.\n");
} else{
puts("debug is a file.\n");
}
return 0;
}

------------------------------------------------
"debug" 是我指定要判斷的資料路徑
如果 debug 是資料夾的話就會輸出 debug is a dir
否則會輸出 debug is not a dir

arrow
arrow
    全站熱搜

    inmyworld 發表在 痞客邦 留言(0) 人氣()