原帖由
chinahelloworld 於 2008-8-7 17:20 發表

這一段只能顯示文件名字,並且順序也沒有規律,也即不知道它列出的文件名是按照什麼順序排的。
大小的話,我用file_stat.st_size,出來的大小都一樣的
不至於吧。但是你給的 code 沒寫這部份啊....
還有我的目的是要做一個和 shell中的ls -l或者ll命令一樣的程序。搞不來啊,鬱悶。本來就是菜鳥,現在還靠linux編程混飯吃,哎
我用if(S_ISDIR(file_stat.st_mode))。。。。。
編譯能過,但是S_ISDIR(file_stat.st_mode)的值總是假,不知道為什麼,本來按道理,如果是是目錄的話,應該為真啊
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
struct stat buf;
stat("/etc",&buf);
if (S_ISDIR(buf.st_mode) == 0)
printf("\n\t/etc is not directory !\n\n");
else
printf("\n\t/etc is directory !\n\n");
return 0;
}