我如何获得一个文件名的命令行参数的完整路径? [英] How do I get the full path for a filename command-line argument?

查看:189
本文介绍了我如何获得一个文件名的命令行参数的完整路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,许多图书馆,以帮助解析命令行参数,但他们都不给处理处理文件名。如果我收到类似的命令行../foo,我怎么计算出完整的文件路径?

I've found lots of libraries to help with parsing command-line arguments, but none of them seem to deal with handling filenames. If I receive something like "../foo" on the command line, how do I figure out the full path to the file?

推荐答案

POSIX有<一个href=\"http://www.opengroup.org/onlinepubs/007908799/xsh/realpath.html\"><$c$c>realpath().

POSIX has realpath().

#include <stdlib.h>
char *realpath(const char *filename, char *resolvedname);

说明

的真实路径()的派生功能,从由路径指向的文件名的,绝对路径名称相同的文件,其分辨率不涉及。,.. ,或符号链接。所产生的路径被存储,最多的{PATH_MAX}字节,缓冲器由<青霉> resolvedname 的指向

DESCRIPTION
The realpath() function derives, from the pathname pointed to by filename, an absolute pathname that names the same file, whose resolution does not involve ".", "..", or symbolic links. The generated pathname is stored, up to a maximum of {PATH_MAX} bytes, in the buffer pointed to by resolvedname.

这篇关于我如何获得一个文件名的命令行参数的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆