dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Remove Certain list items

  1. #1

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Resolved [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
    Last edited by elmnas; Dec 7th, 2015 at 05:28 AM.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    318

    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

  3. #3

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Re: Remove Certain list items

    thank you work as a charm!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width