使用复杂模式在目录中搜索文件 [英] Search file in directory using complex pattern

查看:96
本文介绍了使用复杂模式在目录中搜索文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个C#库,以便使用类似于Ant中使用的模式的复杂模式从目录中获取文件或目录:

I am looking for a C# library for getting files or directory from a directory using a complex pattern like the one used in Ant:

  • dir1/dir2/**/SVN/*->匹配SVN目录中位于目录树dir1/dir2下任何位置的所有文件
  • **/test/**->匹配路径中包含test元素的所有文件,包括将test作为文件名.
  • ...
  • dir1/dir2/**/SVN/* --> Matches all files in SVN directories that are located anywhere in the directory tree under dir1/dir2
  • **/test/** --> Matches all files that have a test element in their path, including test as a filename.
  • ...

我需要自己编写代码吗?从NAnt提取我想要的东西?或存在这个库,而我的Google技能糟透了.

Do I need to code it myself? extract what I want from NAnt? Or this library exists and my google skill sucks.

Directory.GetFiles(String path, String searchPattern)不处理目录模式,并且 NDepend.Helpers.FileDirectoryPath 都不是(这是一个顺便说一句,很好的用于路径操作的库)

Directory.GetFiles(String path, String searchPattern) doesn't handle directory pattern and NDepend.Helpers.FileDirectoryPath neither (it's a great library for path manipulation by the way)

推荐答案

自己编写代码不会那么难.

Coding it yourself wouldnt be that hard.

只需在System.IO方法中使用正确制定的​​正则表达式即可构建完整路径

Just use a correctly formulated regular expression with System.IO methods to build the full path

这篇关于使用复杂模式在目录中搜索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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