我正在构建多个图库中所有文件的主数组,我希望图像按创建日期/时间的降序显示。我需要帮助在我的脚本中实现OrderBy
。这是正确的方法吗?我真的可以使用一些指导。
// Build Gallery Array
string[] arctopithecusImages = Directory.GetFiles(arctopithecusGalleryPath, "*.jpg");
string[] gulonImages = Directory.GetFiles(gulonGalleryPath, "*.jpg");
string[] scythianWolfImages = Directory.GetFiles(scythianWolfGalleryPath, "*.jpg");
string[] simivulpaImages = Directory.GetFiles(simivulpaGalleryPath, "*.jpg");
string[] succorathImages = Directory.GetFiles(succorathGalleryPath, "*.jpg");
string[] tatusImages = Directory.GetFiles(tatusGalleryPath, "*.jpg");
// Concatenate Gallery Folders into single Array
galleryImages =
Directory.GetFiles(arctopithecusGalleryPath, "*.jpg")
.Concat(gulonImages)
.Concat(scythianWolfImages)
.Concat(simivulpaImages)
.Concat(succorathImages)
.Concat(tatusImages).OrderBy(f => f.All)
.ToArray();
答案 0 :(得分:1)
我认为你应该使用DirectoryInfo
课程。它将为您提供的不仅仅是文件名。然后您就可以按文件属性订购
DirectoryInfo diArctopithecusDirectory = new DirectoryInfo(arctopithecusGalleryPath);
FileInfo[] arctopithecusImages = diArctopithecusDirectory.GetFiles("*.jpg");
DirectoryInfo diGulonImagesDirectory = new DirectoryInfo(gulonGalleryPath);
FileInfo[] arctopithecusImages = diGulonImagesDirectory.GetFiles("*.jpg");
DirectoryInfo diScythianWolfDirectory = new DirectoryInfo(scythianWolfGalleryPath);
FileInfo[] scythianWolfImages = diScythianWolfDirectory.GetFiles("*.jpg");
FileInfo[] result = arctopithecusImages.Union(arctopithecusImages)
.Union(scythianWolfImages)
.OrderByDescending(p => p.CreationTime)
.ToArray();
如果您只需要文件名,则可以执行类似
的操作string[] result = arctopithecusImages.Union(arctopithecusImages)
.Union(scythianWolfImages)
.OrderByDescending(p => p.CreationTime)
.Select(x => x.Name)
.ToArray();