[RESOLVED] Remove Certain list items
Hello people,
I have made a code that generates all paths from folders and sub folders in a certain path.
the list contains like 6000 different items.
I want to remove all list items that contains "junk" or "junk2" the phrases are always the last phrase in the path for the list item example:
C:\X\blablablal\junk
C:\X\blablablal\awdasdasd\junk2
C:\X\adjassdasd\junk
Code:
Dim listofstrings As New List(Of String)
' For Each d In Directory.EnumerateDirectories("X:\1 Övriga kunder\Arkiv\Originalfiler", "*.*", SearchOption.AllDirectories)
For Each d In Directory.EnumerateDirectories("C:\X\", "*.*", SearchOption.AllDirectories)
Dim myPath = ((d.ToString()))
listofstrings.Add(myPath)
'Console.WriteLine(myPath)
Next
For Each Pitem In listofstrings
If Pitem.Contains("junk" or "junk2") Then
Pitem.Remove()
End If
Next
End Sub
Could someone help me with a code that works?
my loop doesn't work
Thank you in advance
Re: Remove Certain list items
Try this
Code:
For Each item As String In listofstrings.ToList
If item.Contains("junk") Then
listofstrings.Remove(item)
End If
Re: Remove Certain list items
thank you work as a charm!