扫描目录中指定后缀名的文件(支持WINDOWS跟LINUX)

这段代码展示了如何在Windows和Linux系统下遍历目录,根据指定的文件后缀进行过滤。通过`scanFilesWithFilter`函数,可以查找包含特定后缀的文件,并打印其完整路径。
摘要由CSDN通过智能技术生成
<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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值