linux C++ & C 读取指定目录下的指定后缀名,去除处扩展名获取名字存至数组
转自https://blog.csdn.net/a503932194/article/details/47830779#include<iostream>#include<stdio.h>#include<unistd.h>#include<dirent.h>#include&l
·
转自https://blog.csdn.net/a503932194/article/details/47830779
#include<iostream>
#include<stdio.h>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<cstring>
#include<stdlib.h>
using namespace std;
/*
参数 第一解析目录地址 第二 截取后存放的数组 第三分隔符即解析后缀
方法返回数组实际长度,注意size-3部分其中3是分隔符长度
解析失败返回-1
*/
int searchdir(const char *path, char *filename[],const char *split)
{
//目录
DIR *dp;
//获取dir目录具体的文件信息,名字,长度,指针地址等
struct dirent *dirp;
if ((dp = opendir(path)) == NULL)
{
perror("opendir");
}
int strL = 0;
while ((dirp = readdir(dp)) != NULL)
{
if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
continue;
int size = strlen(dirp->d_name);
if (strcmp((dirp->d_name + ( size - 3)), ".in")!=0)
continue;
filename[strL++] = strtok(dirp->d_name, split);
}
closedir(dp);
return strL;
}

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)