[RESOLVED] Listbox and file.syste.copydirectory
I have a listbox with a bunch of paths listed in it. when a button is click it goes to each of the directories and copies the files to the destination location.
As each dicretory is copied I want the item to be removed from the list box but it seem i'm not doing something right in my code.
The second issue is it possible to get the directory name of wher the files are being copied from and create that directory at the destination location? Thanks for all the help.
Code:
ToolStripStatusLabel1.Visible = True
For Each itm As String In Me.ListBox1.Items
ToolStripStatusLabel1.Text = itm
My.Computer.FileSystem.CopyDirectory(itm & "\", ComboBox1.Text)
ListBox1.Items.Remove(itm)
Next
MsgBox("File Copy Complete.", MsgBoxStyle.OkOnly, "Copy Complete")
Re: Listbox and file.syste.copydirectory
Try this code:
Code:
Dim items(Me.ListBox1.Items.Count - 1) As Object
Me.ListBox1.Items.CopyTo(items, 0)
Dim dInfo As IO.DirectoryInfo
For Each item As String In items
dInfo = New IO.DirectoryInfo(item)
If dInfo.Exists Then
My.Computer.FileSystem.CopyDirectory(item, Me.ComboBox1.Text)
End If
Me.ListBox1.Items.Remove(item)
Next
Re: Listbox and file.syste.copydirectory
is it possible to use a ToolStripProgressBar to keep track of the progress of each directory?
Re: Listbox and file.syste.copydirectory
You don't need the extra array.
vb.net Code:
Dim item As Object
For index As Integer = myListBox.Items.Count - 1 To 0 Step -1
item = myListBox.Items(index)
'Use item here.
myListBox.Items.Remove(item)
Next item
vb.net Code:
While myListBox.Items.Count > 0
'Use myListBox.Items(0) here.
myListBox.Items.RemoveAt(0)
End While
Re: Listbox and file.syste.copydirectory
Quote:
Originally Posted by Ghost_
is it possible to use a ToolStripProgressBar to keep track of the progress of each directory?
It's possible to update a ProgressBar after each folder, but during the processing of a folder you get no feedback so you can't provide any meaningful feedback to the user. There is more than one overload of CopyDirectory though, and you can specify that it should display its own progress dialogue, just like Windows Explorer does.
Re: Listbox and file.syste.copydirectory
is it possible to have the current directory being copied displayed in a ToolStripStatusLabel? I mainly want to give the user somekind of feedbackon what the progress of the copy is since its gonna be huge files in these directories. Thanks for all the help guys.
Re: Listbox and file.syste.copydirectory
Of course. Within the loop you are getting the path of the folder in order to use it. You can use it however you want. If you want to display it in a label then by all means do so. The path is just a string so you can use that wherever a string is expected.
Re: Listbox and file.syste.copydirectory
i can't seem to get it right.
Code:
Dim items(Me.ListBox1.Items.Count - 1) As Object
Me.ListBox1.Items.CopyTo(items, 0)
Dim dInfo As IO.DirectoryInfo
For Each item As String In items
dInfo = New IO.DirectoryInfo(item)
If dInfo.Exists Then
ToolStripStatusLabel1.Text = dInfo.Name
My.Computer.FileSystem.CopyDirectory(item, Me.ComboBox1.Text & "\" & dInfo.Name)
End If
Me.ListBox1.Items.Remove(item)
Next
Right now I'm have the problem of the lable showing up after its done copying. I want it to show up before it starts copying. :( Thanks for the help
Re: Listbox and file.syste.copydirectory
Your problem is that the UI doesn't get update quickly enough to get in before the copy operation starts. By then it has to wait until the operation is finished before the resources are available to refresh. In that case you need to force the label to refresh. You could try calling the ToolStripStatusLabel's Invalidate method but I'm not sure that that will work. If it doesn't then call the StatusStrip's Refresh method.
Re: Listbox and file.syste.copydirectory
Quote:
Originally Posted by jmcilhinney
You don't need the extra array.
vb.net Code:
Dim item As Object
For index As Integer = myListBox.Items.Count - 1 To 0 Step -1
item = myListBox.Items(index)
'Use item here.
myListBox.Items.Remove(item)
Next item
vb.net Code:
While myListBox.Items.Count > 0
'Use myListBox.Items(0) here.
myListBox.Items.RemoveAt(0)
End While
Well done Jmc ;)