can't sort files from folder in String[] Array

后端 未结 4 934
既然无缘
既然无缘 2021-01-28 04:06

my project is about recording screen as sequence of images then instead of make it as video i planed to load all image directories to list and use timer to view them image by im

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-28 04:24

    The most simple way is to use the OrderBy function in LINQ in combination with Path.GetFileNameWithoutExtension like so:

    string[] array1 = Directory.GetFiles("C:\\Secret\\" + label1.Text, "*.Jpeg");
    array1 = array1.OrderBy(x => int.Parse(System.IO.Path.GetFileNameWithoutExtension(x))).ToArray();
    

    To use the OrderBy function, you need to add a using statement for the namespace System.Linq;

提交回复
热议问题