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

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

问题描述

这个

为什么fopen(any_path_name,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?

推荐答案

man 2 stat

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天全站免登陆