The reason why the program is probably hanging is most likely the way that you're looping. Currently, in my example, I simply looped from 1 to 52. The reason why I looped like that was only for demonstrative purposes, to show you how it would apply. You need to adjust the code to fit your particular need.
Take a look at this example. It does the same thing, only it loops though each checked CheckBox that sits on the form. This assumes that the CheckBox's text holds the path that you want to copy from and you're copying it to some other location but with the same file name:
That example uses JMcIlhinney's suggestion too by the way.Code:Dim exceptions As List(Of Exception) = New List(Of Exception) For Each cb As CheckBox In Me.Controls.OfType(Of CheckBox).Where(Function(c) c.Checked) Try My.Computer.FileSystem.CopyDirectory("fooDirectory" & cb.Text, "newDirectory" & cb.Text) Catch ex As Exception exceptions.Add(ex) End Try Next If exceptions.Count > 0 Then For i As Integer = exceptions.Count - 1 To 0 Step -1 Console.WriteLine(exceptions.Item(i).Message) Console.WriteLine() Next End If
The moral of the story is that you cannot expect to copy/paste code and have it work flawlessly. You need to take the principals applied and adjust it to your situation.




Reply With Quote
