码迷,mamicode.com
首页 > 编程语言 > 详细

linux C++ 获取文件绝对路径

时间:2016-05-07 12:46:15      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

提供ftp服务时需要获取文件绝对路径,这里记录一下。

 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 #include <limits.h>
 4 
 5 int main(){
 6     const char *file_name = "filename";
 7     char abs_path_buff[PATH_MAX];
 8 
 9     //获取文件路径, 填充到abs_path_buff
10     //realpath函数返回: null表示获取失败; 否则返回指向abs_path_buff的指针
11     if(realpath(file_name, abs_path_buff)){
12         printf("%s %s\n", file_name, abs_path_buff);
13     }
14     else{
15         printf("the file ‘%s‘ is not exist\n", file_name);    
16     }
17 
18     return 0;
19 }

 

linux C++ 获取文件绝对路径

标签:

原文地址:http://www.cnblogs.com/xudong-bupt/p/5467735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!