VB.net: How do I retrieve a file's directory location from a checkedlistbox within a loop function?

You can post your problem related to Microsoft Visual Studio Projects here. We will try our best to help you out.
Post Reply
Posts: 18
Joined: Sat Feb 18, 2017 9:10 am

VB.net: How do I retrieve a file's directory location from a checkedlistbox within a loop function?

Post by Johnson » Tue Mar 07, 2017 9:03 am

Okay, what I have is a program that reads from 2 selected folders. The way it works is by means of 2 separate "Browse" buttons that utilizes it's own folder browser dialog function. upon selecting the first folder, the folder contents populate a checked list box. the same goes for the second "Browse" button. However, the second button will populate not only the folder contents, but all sub-files as well.

Check box list 1(Folder 1/Selected from button1)

Check box list 2(Folder 2/selected from button2)

Folder 3(not seen in list)

Panels AB01.dwg
Folder 4(not seen in list)

Rake BA01.dwg
Folder 5(not seen in list)

Rafter CA01.dwg
Folder 5(not seen in list)

Column DA01.dwg
Now, I have 2 functions in the code. One looks for the name from list 1 and copies/renames the file with name from list 2 if the name from list 2 contains the same characters from list 1.

Code: Select all

    Function FindListBox2ItemThatContains(ByVal listBox1FileName As String) As String

        For i As Integer = 0 To ListBox2.Items.Count - 1
            If ListBox2.Items(i).Name.Trim.toupper.Contains(listBox1FileName.Trim.ToUpper) Then
                Return ListBox2.Items(i).Name.trim
            End If
        Return ""

    End Function
next, i have a third button that runs the code, and copies/pastes the new files into location using the file from list 1 and renames it with the file from list 2. the saved location used to be specified by the user, but now i need the code to just overwrite the file from list 1 in it's current location. Here's the existing loop function...(note: the new path hasn't been finalized yet because i don't know how to code for it.

Code: Select all

For Each file As IO.FileInfo In ListBox1.CheckedItems

            Dim NewFileName As String = FindListBox2ItemThatContains(file.Name)
            If NewFileName.Trim.Length > 0 Then IO.File.Copy(file.FullName, IO.Path.Combine(FBD2.SelectedPath, "item parent folder", NewFileName.Trim), True)

how do i retrieve the file location from list 2, and save the new file in that location?


Post Reply