C语言检测对象是文件还是文件夹的代码

把开发过程中比较常用的代码片段做个珍藏,如下的代码是关于C语言检测对象是文件还是文件夹的代码,应该能对各位朋友有用途。
bool file_exists
(
)
{
bool Exists;
struct stat Info;
if (stat(Pathname, &Info) == 0)
{
Exists = S_ISREG(Info.st_mode);
}
else
{
Exists = false;
return
Exists;





检测是否是文件夹


bool directory_exists
(
bool FollowSymlink
)
{
bool Exists;
struct stat Info;
if
(
(FollowSymlink ?
stat(Pathname, &Info)
:
lstat(Pathname, &Info)
)
==
0
)
{
Exists = S_ISDIR(Info.st_mode);
}
else
{
Exists = false;
return
Exists;




原文地址:https://www.cnblogs.com/codeoldman/p/10372816.html