怎么知道一串字符是文件还是文件夹,附上代码。
//头文件
#include "stdio.h"
#include "stdlib.h"
#include <sys/stat.h>
//代码
int main()
{
char* fileName = "bb";
struct _stat buf;
int result;
result = _stat(fileName, &buf);
if (_S_IFDIR & buf.st_mode) {
printf("folder\n");
}
else if (_S_IFREG & buf.st_mode) {
printf("file\n");
}
system("pause");
return 0;
}
通过C++代码实现判断给定路径是文件还是文件夹,详细代码示例。
340





