文件名匹配算法(windows下的[*?])

C语言通配符匹配、文件名通配符匹配算法(wildchar.c) 文件名通配符,比如:*.txt,?.txt。一个通配符匹配算法,一个ANSI C函数就OK了 立即下载
/*

 fn_compare.hpp

 sdragonx 2015-02-25 14:32:54

*/
#ifndef FN_COMPARE_HPP_20150225143254
#define FN_COMPARE_HPP_20150225143254

#include <string>

#define _CGL_BEGIN cgl{
#define _CGL_END }

#define cstring std::basic_string

_CGL_BEGIN

/*
 模糊查找文件名matching
 例:
 bool b = fn_compare("abc.txt", "a?c.*");

 sdragonx 2010-09-20 16:01
*/

template<typename _char_t>
bool fn_compare(const cstring<_char_t>& fname, const cstring<_char_t>& findstr)
{
    //const static cstring<_char_t> mark = "*?";
    _char_t mark[4] = { '*', '?' };
    if(fname.empty() || findstr.empty())
    {
        return false;
    }
    if(findstr.find_first_of(mark) == cstring<_char_t>::npos)
    {
        return fname.find(findstr) != cstring<_char_t>::npos;
    }
    else
    {
        size_t n = 0;
        for(size_t i = 0; i<findstr.size(); )
        {
            if(findstr[i] == '*')
            {
                i = findstr.find_first_not_of(mark, i);
                if(i == cstring<_char_t>::npos){
                    return true;
                }
                n = fname.find(findstr[i], n);
                if(n == cstring<_char_t>::npos){
                    return false;
                }
            }
            else if(findstr[i] == '?')
            {
                ++n;
                ++i;
            }
            else
            {
                //while(mark.find(findstr[i]) == cstring<_char_t>::npos)
                while(findstr[i] != '*' && findstr[i] != '?')
                {
                    if(!findstr[i]){
                        return true;
                    }
                    else if(fname[n++] != findstr[i++]){
                        return false;
                    }
                }
            }
        }
        return !(n < fname.size());
    }
}

_CGL_END

#endif //FN_COMPARE_HPP_20150225143254

应用:

char* filename = "abc/a.txt";

bool n = fn_compare(filename, "abc/*.tx?");
n == yes

bool n = fn_compare(filename, "abc/*.bmp");
n == no

bool n = fn_compare(filename, "a?c/*.txt");
n == yes

DOS/Windows的文件名通配符 DOS/Windows的文件名通配符,比如:*.txt,?.txt。上次介绍了一个正则表达式的方法,这次自已写一 个通配符匹配算法,一个函数就OK了(ANSI C的)。 立即下载

相关推荐

bat模糊搜索命令

可以在bat所在的目录模糊搜索文件并打开

C++将文件夹文件分类

// ForTransferFlies.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "stdio.h" #include "stdlib.h" #include <string> #include <string.h> #include <sys/stat.h> #include <sstream> #include <iostream> #include <fstream&gt

Cream_Cicilian的博客 1229

【史诗级】详细阐述借助AI实现对Windows蓝屏原因进行精确定位的方法

在解决问题的过程中我决定把这一切都记录下来,并整理出一套通用的方法,方便快速精确定位引起蓝屏的真实原因。今天我的蓝屏代码是0x000000ef,而你或许是遇到另一个蓝屏代码,代码本身代表的含义不是这里的讨论重点,重要的是解决问题的底层逻辑。

sprlightning的博客 1万+

mysql 匹配任意字符_MySQL入门-6:通配符匹配和正则表达式

大纲1、文件名匹配2、LIKE操作符3、使用正则表达式一、文件名匹配在Windows的CMD命令行和Linux的Bash中,都支持文件名通配,但是这个匹配能力非常弱,由于仅用于匹配文件名,所以也不算什么缺陷。比如我想查看后缀名为.txt的所有文件:#ls*.txt通常支持的通配符有:* 匹配任意字符任意次? 仅匹配任意单个字符[0-9a-zA-Z] 字符集,匹配任意列出...

weixin_35513543的博客 4902

在ZYNQMP上点亮800x480 LCD屏:从framebuffer到DRM框架的完整驱动移植实战

本文详细介绍了在ZYNQMP平台上点亮800x480 LCD屏的完整驱动移植实战,从framebuffer到DRM框架的技术实现。内容涵盖硬件配置、设备树设置、显示时序参数调试以及DRM驱动核心实现,帮助开发者快速掌握PetaLinux系统中的LCD驱动开发技巧。

weixin_33701294的博客 427

别再死记硬背公式了!用ADS手把手教你仿真一个4GHz镜像抑制混频器(附完整工程文件)

本文详细介绍了使用Keysight ADS软件设计和仿真4GHz镜像抑制混频器的完整流程。从理论分析到实际工程实现,涵盖分支线耦合器设计、二极管建模、噪声系数仿真及性能优化等关键步骤,帮助工程师摆脱公式死记硬背,掌握实用的射频电路设计技能。附完整工程文件,可直接应用于实际项目开发。

weixin_28683391的博客 496

bat匹配部分文件名移动至目标文件夹

bat匹配部分文件名移动至目标文件夹

2658

Android图形系统(三)系统篇:渲染/合成的底层原理浅析

众所周知,渲染工作是由GPU负责,那么在聊GPU之前首先得知道什么是“渲染”?我们来举个例子感受一下在系统中申请一块10*101、把图层背景这玩意染成绿的2、从左上(0,0)到右下(10,10)画一条宽度为1颜色为红色的直线3、以坐标点(5,5)为中心,画一个半径为3的实心圆,颜色要蓝色好了,接下来操作系统会把这些“绘图指令”同步给GPU去执行渲染任务图片来源:自己画的GPU完成渲染工作后,我们将会得到一个大小为10*10二维数组,数组中的每个元素都保存着坐标点的颜色信息、深度信息。

1357

cmd通过文件名和大小匹配替换

cmd bat 文件大小 文件名 匹配 替换

ERIZHU的博客 564

Yolov8-pose关键点检测:通用倒瓶颈(UIB)搜索块结合C2f二次创新 | 轻量化之王MobileNetV4

通用倒瓶颈(UIB)搜索块结合C2f二次创新

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 613

DeerFlow 系列教程 第三篇 | 核心技术深度剖析:Skills、Memory 与 Context Engineering

摘要化是 Context Engineering 中最关键的组件——它直接决定了长对话的可用性。Skills 技能系统通过渐进式加载的三层模型,在保持系统提示词轻量的同时,支持无限数量的技能扩展。从发现到执行的 10 个生命周期阶段,配合 AI 驱动的安全扫描和多层缓存,构成了一个生产级的技能管理框架。Memory 长期记忆系统通过文件系统持久化、LLM 驱动的信息提取和防抖动异步更新,实现了跨会话的认知持久化。六类事实分类体系和修正信号检测机制,让 Agent 能够从交互中持续学习和改进。

weixin_43674738的博客 280

文件名通配符匹配算法

什么是文件名通配符如何实现带有?*通配符的字符串(string)匹配呢,可以把问题拆开看只含有?的模型(pattern),和只含有*的模型只含有?的模型理解起来非常简单,因为?就等于一个字符,含有?的模型就等于一个字符串判断是否匹配,只要在给定字符串中,查找含有?的字符串就行了,而在字符串中查找字符串就是用indexOf.只不过现有的indexOf,不知道?就代表任意字符,所以需要自己动手改写

hbb的专栏 5972

Android 9.0 SystemUI禁用长按recent键的分屏功能

​ 在9.0的系统产品开发中,系统对于多窗口模式默认会有分屏功能的,但是在某些产品中,需要禁用分屏模式,所以需要在导航栏中 禁用长按recent的分屏模式功能,接下来分析下相关分屏模式的实现 ​

安卓兼职framework和app工程师的博客 448

windows下如何检测文件名大小写不匹配

iOS和android(还有linux)都是文件名大小写敏感的,windows是大小写不敏感的。         这样游戏开发的时候就会出现这样的问题,windows下测试正常的游戏(包括mac下的iOS模拟器运行正常的游戏,因为Mac系统也是文件名大小写不敏感的),放到实际设备上运行可能各种崩溃。其中十有八九是配置文件名和实际文件名不匹配造成的。         解决方法有:

langresser的专栏 5733

Rancher入门到精通 - Nginx Ingress 配置指南

Rancher 是一个开源的容器管理平台,它提供了一套完整且易于使用的工具来部署、管理和扩展容器化应用。而 Nginx Ingress 则是一个常用的开源 Ingress 控制器,用于将外部请求流量导入到 Kubernetes 集群中的服务。在开始之前,请确保您已经正确安装了 Rancher 平台和 Nginx Ingress 控制器。

TechInk的博客 1311

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Windows系统使用bat批量修改文件名

Windows系统使用bat文件批量修改文件名。

weixin_56337147的博客 7478

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python文件名通配符_Python3标准库:glob文件名模式匹配

1. glob文件名模式匹配尽管glob API很小,但这个模块的功能却很强大。只要程序需要查找文件系统中名字与某个模式匹配的一组文件,就可以使用这个模块。要创建一个文件名列表,要求其中各个文件名都有某个特定的扩展名、前缀或者中间都有某个共同的字符串,就可以使用glob而不用编写定制代码来扫描目录内容。glob的模式规则与re模块使用的正则表达式并不相同。实际上,glob的模式遵循标准UNIX路径...

weixin_39564524的博客 1258

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Python 规范文件名

文件名中不能含有以下字符,否则会报错。

Show me the code. 1626

Windows文件名正则表达式

^[^/\\\\:\\*\\?\\\\|\"]{1,255}$

guobutter的博客 2411

Windows 批处理脚本:3行代码批量删除文件名前缀,支持通配符匹配

本文详细介绍了如何使用Windows批处理脚本通过3行核心代码批量删除文件名前缀,支持固定前缀和通配符匹配。文章提供了基础版、进阶版和高级版脚本示例,涵盖正则表达式处理、性能优化及安全防护等实用技巧,帮助用户高效管理文件命名。

weixin_28314575的博客 350

Folia PWA 手机安装指南:15 分钟部署,把全屏歌词动画播放器装进主屏幕

Folia 是一款以全屏沉浸式歌词动画著称的音乐播放器,音源覆盖网易云、QQ 音乐、酷狗、Navidrome 与本地曲库。这篇指南解决一个问题:怎么让手机拥有一个带图标、全屏无地址栏的 Folia。做法是把 Web 版部署到你能访问的地址,用浏览器把它装成 PWA(Progressive Web App,即"可安装到主屏幕的网页应用",启动后像原生 App 一样独占整个屏幕),再连上 Navidr

gitblog_00856的博客 431

Windows Explorer 文件名排序算法

Windows Explorer里对文件名的排序有别于普通字符串字典序排序。

无标题 1315

利用正则表达式从文件路径中匹配文件名

第一种,文件名不包含扩展名: 正则表达写法:([^ java中的写法: …… String reg = "([^<>/\\\\|:\"\"\\*\\?]+)\\.\\w+$+"; Matcher m = Pattern.compile(reg).matcher(uri); //uri为需要匹配的路径 Sring filename = null; if

a785975139的博客 4万+

Windows 文件路径与文件名限制

历史兼容性命令语法解析系统安全性与稳定性作为开发者,理解这些约束,编写跨平台兼容的代码、命名规范一致的文件结构,是开发现代软件系统的基础素养之一。

侯仕奇的博客 2296
上一篇: c++ 字符串分割函数stringsplit
下一篇: c++ delegate 最大16个参数,用程序生成的代码
sdragonx
博客等级 码龄19年 20粉丝 46原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值