I am trying to load all images from a folder if the filename contains a specific number

Viewed 60

So, I have this code and it is loading all images into a list. I am trying to make it so that if the filenames are made like for examlple: filetype_1_A filetype_2_A etc. that it will only put the type 1 into the list. But I can't figure it out.

public static List<string> createImgs(string src) {
    List<string> list = new List<string>();
    
    foreach (string file in Directory.EnumerateFiles(src, "*.png")) {
        string contents = createImg(file.Replace(@"wwwroot\", "")).OuterHtml;

        if (contents == "<img src=\"assets\\img\\filetype_1_"_".png\">") {
            list.Add(contents);
        }
    }
    return list;
}
1 Answers

You can simply include it in the filter expression :

Directory.EnumerateFiles(src, "filetype_1_*.png")
Related