如何检查这是否是目录路径或任何文件路径? [英] How can I check whether this is directory-path or any filename-path?

查看:97
本文介绍了如何检查这是否是目录路径或任何文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href=\"http://stackoverflow.com/questions/8399475/why-does-fopenany-path-name-r-not-give-null-as-return\">Why不FOPEN(QUOT; any_path_name&QUOT;,'R')?不给NULL作为回报

我可以知道,在linux目录和文件被认为是文件。所以,当我在给出的fopen与读模式的任何目录路径或文件路径它不给空文件描述符和?

i get to know that in linux directories and files are considered to be file. so when i give any directory-path or file-path in fopen with read mode it doesnt give NULL file descriptor and?

所以我怎样才能检查它是否是dirctory路径或文件路径?如果我收到来自命令参数的一些路径?

so how can i check that whether it is dirctory path or file-path ? if i am getting some path from command argument?

推荐答案

2人统计

NAME
     fstat, fstat64, lstat, lstat64, stat, stat64 -- get file status

...

     struct stat {
         dev_t           st_dev;           /* ID of device containing file */
         mode_t          st_mode;          /* Mode of file (see below) */

...

     The status information word st_mode has the following bits:

...

     #define        S_IFDIR  0040000  /* directory */

这篇关于如何检查这是否是目录路径或任何文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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