2009年2月18日 星期三

測試檔案是否存在

c library中有access函式可以用來測試檔案的狀況。

Example:

#include <unistd.h>
int main(){

int r = access("a.txt", F_OK);
if(r==-1)
printf("File doesn't exist.\n");
else
printf("File exists.\n");

}


參考網址:
http://www.gnu.org/software/libtool/manual/libc/Testing-File-Access.html

沒有留言:

張貼留言