<pre name="code" class="cpp">#ifdef WIN32
#include <windows.h>
#define strcasecmp stricmp
#define strncasecmp strnicmp
#define PATH_SPLITER '\\'
#else
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#define PATH_SPLITER '/'
#endif
#include <stdio.h>
#include <string.h>
int scanFilesWithFilter(char* rpath,char* filter=".txt");
//******************************************
// Method: scanFiles
// 扫描任务路径并以指定的后缀名进行过滤
// Returns: void
// Parameter:
// char* rpath
// char* filter
//******************************************
int scanFilesWithFilter(char* rpath,char* filter/* =".txt" */)
{
if (!filter)
{
filter=(char*)".txt";
}
#ifndef WIN32
DIR *dirp = NULL;
if (!(dirp = opendir(rpath)))
{
return -1;
}
struct dirent *pdt = NULL;
while (pdt = readdir(dirp))
{
char *pos=s
扫描目录中指定后缀名的文件(支持WINDOWS跟LINUX)
最新推荐文章于 2022-09-07 17:27:19 发布
这段代码展示了如何在Windows和Linux系统下遍历目录,根据指定的文件后缀进行过滤。通过`scanFilesWithFilter`函数,可以查找包含特定后缀的文件,并打印其完整路径。
摘要由CSDN通过智能技术生成