简体   繁体   English

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

[英]c# How to get filepaths for ALL items in a resource folder

I'm trying to create a list with BitmapImages like this. 我试图用这样的BitmapImages创建一个列表。

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

Right now I'm adding one image manually from the resource \\Images\\, but I don't want to do that for all 68 images. 现在,我要从\\ Images \\资源中手动添加一幅图像,但是我不想对所有68张图像都这样做。 Is there a way to make a method, that will look through the resources \\Images\\, and output a list of all the BitmapImage paths like above? 有没有一种方法可以查看资源\\ Images \\,并输出所有如上所述的BitmapImage路径的列表?

something like. 就像是。

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

Here is a picture of the folder am talking about: 这是正在谈论的文件夹图片:

文件夹结构图

Here how you can get files by pattern 在这里,您如何通过模式获取文件

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images");
foreach (string file in Directory.GetFiles(path, "*.bmp"))
{
    // there is file name
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM