从我的项目/解决方案中的文件夹中获取所有图像 [英] Get all images from a folder in my project/solution
问题描述
一个简单的问题.
我如何以最简单,最安全的方式从解决方案中的文件夹中获取所有图像,而不必将其复制到调试文件夹中.
How do i in the easiest and securest way get all images from a folder in my solution without having to copy them to the debug folder.
所以可以说这是我的文件夹结构:
So lets say this is my folder structure:
Project
Resources (Folder)
Images (Folder)
HelpIcons (Folder)
Icon1.png
Icon2.png
如何从代码中获取icon1和icon2? (无需复制即可调试)
How do i get the icon1 and icon2 from the code? (without copy to debug)
推荐答案
您可以从指定的目录中使用GetFiles.
You can use GetFiles from the directory you specified.
String[] filenames = System.IO.Directory.GetFiles("Project\\Resources\\Images\\HelpIcons");
filenames
包含该目录中所有文件名的列表,然后您可以从此处查找".png"
filenames
contains a list of all filenames in that directory, from here you can then look for ".png"
-编辑12:13-
这将从可执行文件所在的目录开始. 您可以根据需要指定完整路径.
This will be starting from the directory where your executable is. You can specify the full path if needed.
String[] filenames = System.IO.Directory.GetFiles("C:\\Project\\Resources\\Images\\HelpIcons");
这篇关于从我的项目/解决方案中的文件夹中获取所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!