DirectoryInfo.getFiles 开头

发布于 2024-07-29 16:49:50 字数 399 浏览 4 评论 0原文

我在尝试获取以特定字符串开头的文件时遇到了一些奇怪的行为。

请有人给出一个关于此的工作示例:

我想获取目录中以某个字符串开头但也包含 xml 扩展名的所有文件。

例如:

 apples_01.xml
 apples_02.xml
 pears_03.xml

我希望能够获取以 apples 开头的文件。

到目前为止我有这段代码

 DirectoryInfo taskDirectory = new DirectoryInfo(this.taskDirectoryPath);
 FileInfo[] taskFiles = taskDirectory.GetFiles("*.xml");

I've come across some strange behavior trying to get files that start with a certain string.

Please would someone give a working example on this:

I want to get all files in a directory that begin with a certain string, but also contain the xml extension.

for example:

 apples_01.xml
 apples_02.xml
 pears_03.xml

I want to be able to get the files that begin with apples.

So far I have this code

 DirectoryInfo taskDirectory = new DirectoryInfo(this.taskDirectoryPath);
 FileInfo[] taskFiles = taskDirectory.GetFiles("*.xml");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱&纷飞 2024-08-05 16:49:50
FileInfo[] taskFiles = taskDirectory.GetFiles("apples*.xml");
FileInfo[] taskFiles = taskDirectory.GetFiles("apples*.xml");
绻影浮沉 2024-08-05 16:49:50
var taskFiles = taskDirectory.GetFiles("*.xml").Where(p => p.Name.StartsWith("apples"));
var taskFiles = taskDirectory.GetFiles("*.xml").Where(p => p.Name.StartsWith("apples"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文