您的位置:首页 > 其它

access函数测试指定路径中是否有某个文件存在

2012-05-09 19:52 357 查看
#include <iostream>
#include <string>
#include <io.h>
using namespace std;

//文件是否存在

int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}

int main( void )
{
printf("E盘有a.txt文件吗?: %s\n",
file_exists("e:/a.txt") ? "YES" : "NO");

system( "PAUSE" );
return EXIT_SUCCESS;
}

/*--------
E盘有a.txt文件吗?: YES
请按任意键继续. . .
---------------------------------*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: