Results 1 to 10 of 10

Thread: [RESOLVED] Listbox and file.syste.copydirectory

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Posts
    23

    Resolved [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")

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Posts
    23

    Re: Listbox and file.syste.copydirectory

    is it possible to use a ToolStripProgressBar to keep track of the progress of each directory?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Listbox and file.syste.copydirectory

    You don't need the extra array.
    vb.net Code:
    1. Dim item As Object
    2.  
    3. For index As Integer = myListBox.Items.Count - 1 To 0 Step -1
    4.     item = myListBox.Items(index)
    5.  
    6.     'Use item here.
    7.  
    8.     myListBox.Items.Remove(item)
    9. Next item
    vb.net Code:
    1. While myListBox.Items.Count > 0
    2.     'Use myListBox.Items(0) here.
    3.  
    4.     myListBox.Items.RemoveAt(0)
    5. End While
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Posts
    23

    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Posts
    23

    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

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Listbox and file.syste.copydirectory

    Quote Originally Posted by jmcilhinney
    You don't need the extra array.
    vb.net Code:
    1. Dim item As Object
    2.  
    3. For index As Integer = myListBox.Items.Count - 1 To 0 Step -1
    4.     item = myListBox.Items(index)
    5.  
    6.     'Use item here.
    7.  
    8.     myListBox.Items.Remove(item)
    9. Next item
    vb.net Code:
    1. While myListBox.Items.Count > 0
    2.     'Use myListBox.Items(0) here.
    3.  
    4.     myListBox.Items.RemoveAt(0)
    5. End While
    Well done Jmc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width