Check box list 1(Folder 1/Selected from button1)
AB01.dwg
BA01.dwg
CA01.dwg
DA01.dwg
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
Next
Return ""
End Function
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)
ProgressBar1.Increment(+1)
Next