0

To make a long story short, Mp3Tag for example, adds folders 1 to 5 first to last. When I add the same folders in my program it adds the folders from 5 (first) to 1 (last). Is there a way I can fix this?

Here's the code I've been using.

    If FolderBrowserDialogMain.ShowDialog = DialogResult.OK Then
        For Each mp3 In Directory.GetFiles(FolderBrowserDialogMain.SelectedPath, "*.mp3", IO.SearchOption.AllDirectories)
            Dim fiFileInfo As New FileInfo(mp3)
            ListViewMain.Items.Add(fiFileInfo.Name)
        Next
    End If
Neil
  • 13
  • 2
  • 1
    Check out [Linq](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderby?view=netframework-4.8). Just add an `.OrderBy(...)` on your `GetFiles(...)`. – RobIII Dec 16 '19 at 18:47
  • Does this answer your question? [Sort a List of Object in VB.NET](https://stackoverflow.com/questions/11735902/sort-a-list-of-object-in-vb-net) – 41686d6564 stands w. Palestine Dec 16 '19 at 18:50
  • You probably want to order by the file name (not the full path). In that case, you could use something like `Dim dirInfo As New DirectoryInfo(FolderBrowserDialogMain.SelectedPath)` and then `For Each fInfo As FileInfo In dirInfo.GetFiles(...).OrderBy(Function(x) x.Name)`. – 41686d6564 stands w. Palestine Dec 16 '19 at 18:54
  • Thanks Robil. I'll check out linq and see what happens. – Neil Dec 16 '19 at 18:57
  • Ahmed thanks for your input. I'll definitely look into all the answers. Thanks guys. – Neil Dec 16 '19 at 19:00

1 Answers1

-2

Maybe add .Reverse to reverse the files?

If FolderBrowserDialogMain.ShowDialog = DialogResult.OK Then
    For Each mp3 In Directory.GetFiles(FolderBrowserDialogMain.SelectedPath, "*.mp3", IO.SearchOption.AllDirectories).Reverse()
        Dim fiFileInfo As New FileInfo(mp3)
        ListViewMain.Items.Add(fiFileInfo.Name)
    Next
End If
C.M.
  • 1,474
  • 13
  • 16