0

I have a directory with files named by "Artist [Style] Number.ext"

An example:

Atomix [Dubstep] 01.avi
Atomix [Rock] 02.wmv
Atomix [Rock] 03.avi

Lacuna [Rock] 01.mp4
Lacuna [Rock] 02.avi

I want to use LINQ to list the files to group them by Artists, in the ordering I want to include only one "[style]" and then sort each artist by file extension, for example like this where I have included only the "[Rock]" style:

Atomix [Rock] 03.avi
Atomix [Rock] 02.wmv
Lacuna [Rock] 02.avi
Lacuna [Rock] 01.mp4

"A" goes first than "L" and "avi" goes first than "wmv", That's my desired result but what I get when trying to ordering is this kind of sort:

Atomix [Rock] 03.avi
Lacuna [Rock] 02.avi
Lacuna [Rock] 01.mp4
Atomix [Rock] 02.wmv

The artists are mixed but the extensions are sorted, "avi" goes first than "mp4" when sorting but "A" of "Atomix" goes first than "L" of "Lacuna", I don't know how to correct this.

This is the instruction I'm using with the filenames I've said before:

    Dim Videos As List(Of IO.FileInfo) = _
    Get_Files(Directory, True, ValidExtensions) _
    .OrderBy(Function(x) x.Extension) _
    .Where(Function(x) x.Name.ToLower.Contains("[rock]")) _
    .ToList

PS: I've tried to toggle the order of the methods but I get the same result.

UPDATE:

I've tried to use the @jyparask solution but I still need some modification to get the extensions ordered, this is what I get:

Aa [Style] 04.mp4
Ab [Style] 01.wmv
Ab [Style] 03.wmv
Ab [Style] 05.mp4
Ab [Style] 05.wmv
Ab [Style] 06.mp4
Ab [Style] 07.mp4
Ab [Style] 09999999999964.mp4
Ac [Style] 166333226.mp4
Ac [Style] 333133333333313313322.mp4
Ac [Style] 44.mp4
Ac [Style] 6049.wmv

And this is the code I'm using:

    Dim Videos As List(Of IO.FileInfo) = _
    Get_Files(Directory, True, ValidExtensions) _
    .Where(Function(x) x.Name.ToLower.Contains("[word]")) _
    .OrderBy(Function(x) x.Name) _
    .ThenBy(Function(x) x.Extension) _
    .ToList()
4

1 回答 1

5

您必须首先 OrderBy the Artist 并使用 ThenBy 传递扩展名。

Dim Videos As List(Of IO.FileInfo) = _
Get_Files(Directory, True, ValidExtensions) _
.OrderBy(Function(x) x.Name.Substring(0,x.Name.IndexOf("["))) _
.ThenBy(Function(x) x.Extension) _
.Where(Function(x) x.Name.ToLower.Contains("[rock]")) _
.ToList
于 2013-08-09T20:30:32.277 回答