匹配“..\ThirdParty\dlls\*.dll”的文件名
有没有一种简单的方法来获取与文件名模式匹配的文件名列表包括对父目录的引用?我想要的是 "..\ThirdParty\dlls\*.dll"
返回一个像 ["..\ThirdParty\dlls\one.dll", "..\ ThirdParty\dlls\two.dll", ...]
我可以找到几个与匹配文件名相关的问题,包括完整路径、通配符,但在模式中没有任何包含“..\”的问题。 Directory.GetFiles
明确禁止它。
我想要对这些名称执行的操作是将它们包含在 zip 存档中,因此,如果有一个 zip 库可以理解这样的相对路径,我会更乐意使用它。
模式来自输入文件,它们在编译时是未知的。它们可能变得非常复杂,例如 ..\src\..\ThirdParty\win32\*.dll
因此解析可能不可行。
必须将其放入 zip 也是我不太热衷于将模式转换为完整路径的原因,我确实想要 zip 中的相对路径。
编辑: 我正在寻找的实际上是 /bin/ls 的 C# 等效项。
Is there an easy way to get a list of filenames that matach a filename pattern including references to parent directory? What I want is for "..\ThirdParty\dlls\*.dll"
to return a collection like ["..\ThirdParty\dlls\one.dll", "..\ThirdParty\dlls\two.dll", ...]
I can find several questions relating matching files names including full path, wildcards, but nothing that includes "..\" in the pattern. Directory.GetFiles
explicitly disallows it.
What I want to do with the names is to include them in a zip archive, so if there is a zip library that can understand relative paths like this I am happier to use that.
The pattern(s) are coming from an input file, they are not known at compile time. They can get quite complex, e.g ..\src\..\ThirdParty\win32\*.dll
so parsing is probably not feasible.
Having to put it in zip is also the reason I am not very keen on converting the pattern to fullpath, I do want the relative paths in zip.
EDIT: What I am looking for really is a C# equivalent of /bin/ls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Path.GetFullPath() 函数可以将相对路径转换为绝对路径。您可以在路径部分使用它。
There is the Path.GetFullPath() function that will convert from relative to absolute. You could use it on the path part.
如果我理解正确,您可以将
Directory.EnumerateFiles
与这样的正则表达式结合使用(但我还没有测试过):If I understand you correctly you could use
Directory.EnumerateFiles
in combination with a regular expression like this (I haven't tested it though):