dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Populate ComboBox With All folder Files Except 1 and cut long Path name

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2012
    Posts
    111

    Resolved [RESOLVED] Populate ComboBox With All folder Files Except 1 and cut long Path name

    Hi guys I have A comboBox and I am populating it with all the files in a particular folder.
    I have 5 files and 3 folders with other files inside all in the main folder.
    I'm populating the CBox with a For Each loop it works fine but I want to add an exception to the "images" folder.
    I tried " If dir <> 'images' " but doesn't seem to work
    How do I do that?

    I also want to cut down the long path to file names to just eg. "index.html"

    I tried the split method but is not doing anything.

    "pjDir" is the main folder.

    here's the code:

    Code:
     Sub PopulateCB(ByVal pjDir As String)
            Dim fName As String = ""
            Dim dirName As String = ""
            If pjDir <> "" Then
                For Each Pfiles In My.Computer.FileSystem.GetFiles(pjDir)
                    Dim brkStr() As String = Pfiles.Split("/")
                    fName = brkStr(brkStr.Length - 1)
                    Form1.CBox.Items.Add(fName)
                Next
                For Each Dirs In My.Computer.FileSystem.GetDirectories(pjDir)
                    For Each Pfiles2 In My.Computer.FileSystem.GetFiles(Dirs)
                        Dim brkStr() As String = Pfiles2.Split("/")
                        fName = brkStr(brkStr.Length - 1)
                        Form1.CBox.Items.Add(fName)
                    Next
    
                Next
    
            End If
    
        End Sub
    Any help is welcome,
    Mike

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Populate ComboBox With All folder Files Except 1 and cut long Path name

    Try this
    Code:
        Sub PopulateCB(ByVal pjDir As String)
            If pjDir <> "" Then
                For Each Pfiles In My.Computer.FileSystem.GetFiles(pjDir)
                    CBox.Items.Add(IO.Path.GetFileName(Pfiles))
                Next
    
                For Each Dirs In My.Computer.FileSystem.GetDirectories(pjDir)
                    If IO.Path.GetFileName(Dirs).ToLower <> "images" Then
                        For Each Pfiles In My.Computer.FileSystem.GetFiles(Dirs)
                            CBox.Items.Add(IO.Path.GetFileName(Pfiles))
                        Next
                    End If
                Next
    
            End If
    
        End Sub



  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2012
    Posts
    111

    Re: Populate ComboBox With All folder Files Except 1 and cut long Path name

    Thanks a lot!
    you're the man!

    Mike

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