0

特定のネットワーク ディレクトリ内のすべてのディレクトリを取得し、それらをリストビューに一覧表示する WPF プログラムがあります。

問題は、非常に多くのディレクトリがあり、リストをロードするのに最大 5 秒かかることです。

より効率的なコードでこれを高速化する方法があるかどうか疑問に思っています。それとも、リストを配列に保存して、最初の変更後に毎回変更を探すだけの方法でしょうか?

For Each i As String In Directory.GetDirectories(dir)
    If File.Exists(Path.GetFullPath(i) & "\cover.jpg") Then
        If (File.GetAttributes(Path.GetFullPath(i)) And FileAttributes.Hidden) <> FileAttributes.Hidden Then
            Dim foldername As String = Path.GetFileName(i)
            Dim moviename As String = foldername
            If moviename.Length > 4 Then
                If moviename.Substring(0, 4) = "The " Then
                    moviename = moviename.Remove(0, 4)
                End If
            End If
            Dim display As Boolean = True
            If IO.Directory.GetDirectories(Path.GetFullPath(i)).Length < 1 Then
                If IO.Directory.GetFiles(Path.GetFullPath(i), "*.avi").Length < 1 Then
                    If IO.Directory.GetFiles(Path.GetFullPath(i), "*.mp4").Length < 1 Then
                        If IO.Directory.GetFiles(Path.GetFullPath(i), "*.mkv").Length < 1 Then
                            display = False
                        End If
                    End If
                End If
            End If
            If display = True Then
                Showslist.Items.Add(New With {Key .img = Path.GetFullPath(i) & "\cover.jpg", .name = foldername, .path = Path.GetFullPath(i), .created = Directory.GetCreationTime(Path.GetFullPath(i)), .moviename = moviename})
            End If
        End If
    End If
Next
4

1 に答える 1