使用Directory.GetFiles与正则表达式状滤波器 [英] Using Directory.GetFiles with regex-like filter

查看:191
本文介绍了使用Directory.GetFiles与正则表达式状滤波器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件的文件夹:




  • Awesome.File.20091031_123002.txt

  • Awesome.File.Summary.20091031_123152.txt



此外,第三方应用程序处理文件内容如下:




  • 读取一个 FOLDERPATH 是searchPattern 从数据库中

  • 执行 Directory.GetFiles(FOLDERPATH,是searchPattern),处理任何文件匹配散装过滤器,然后移动文件存档文件夹。



事实证明,我有我的两个文件移动到不同的存档文件夹,所以我需要处理它们分别由提供不同searchPatterns逐一选择。请注意,我不能修改的第三方应用程序,但我可以修改我的数据库中是searchPattern和文件的目的地。



什么是searchPattern 将让我选择 Awesome.File.20091031_123002.txt 不包括 Awesome.File.Summary.20091031_123152 .TXT


解决方案

Awesome.File。 ???????? _ ??????。TXT




问号(?)作为一个单一的字符占位符。


I have a folder with two files:

  • Awesome.File.20091031_123002.txt
  • Awesome.File.Summary.20091031_123152.txt

Additionally, a third-party app handles the files as follows:

  • Reads a folderPath and a searchPattern out of a database
  • Executes Directory.GetFiles(folderPath, searchPattern), processing whatever files match the filter in bulk, then moving the files to an archive folder.

It turns out that I have to move my two files into different archive folders, so I need to handle them separately by providing different searchPatterns to select them individually. Please note that I can't modify the third-party app, but I can modify the searchPattern and file destinations in my database.

What searchPattern will allow me to select Awesome.File.20091031_123002.txt without including Awesome.File.Summary.20091031_123152.txt?

解决方案

Awesome.File.????????_??????.txt

The question mark (?) acts as a single character place holder.

这篇关于使用Directory.GetFiles与正则表达式状滤波器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆