c#如何获取资源文件夹中所有项目的文件路径

问题描述 投票:2回答:1

我正在尝试使用像这样的BitmapImages创建一个列表。

List<BitmapImage> Images = new List<BitmapImage>
{
    new BitmapImage(new Uri(@"/Images/Car.bmp", UriKind.Relative)),
};

现在我正在从资源\ Images \手动添加一个图像,但我不想对所有68个图像都这样做。有没有办法制作一个方法,它将查看资源\ Images \,并输出所有BitmapImage路径的列表,如上所述?

就像是。

Foreach(Item in Images)
{
    List.add(ItemPath + ItemName)
}

这是我正在谈论的文件夹的图片:

Image of folder structure

c# wpf list file resources
1个回答
6
投票

在这里你如何按模式获取文件

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images");
foreach (string file in Directory.GetFiles(path, "*.bmp"))
{
    // there is file name
}
© www.soinside.com 2019 - 2024. All rights reserved.