Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 25th, 2009, 8:50 AM   #1
Worf
Newbie
 
Join Date: Jan 2009
Posts: 3
Rep Power: 0 Worf is on a distinguished road
Question File search results to listbox help.

Hi.

I am hoping someone here will be able to help me with this probelem?

I have two listbox's on my form, listbox1 which displays a list of files that was found in a search and listbox2 which the user uses to add files from listbox1.

What i am having problems with is that when the user selects an item from listbox1 to add it to listbox2 my program needs to be able to copy the selected file from it's current location to another folder on the hard drive.

Below is part of the code i have at the moment.

Browes Button:
Private Sub Browse_ButtonX2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse_ButtonX2.Click

        ListBoxControl1.Items.Clear()
        Select Case FolderBrowserDialog1.ShowDialog()
            Case DialogResult.OK

                Call FileTypeFinder(FolderBrowserDialog1.SelectedPath, ".wav")
        End Select

    End Sub

Search Routine:
Private Sub FileTypeFinder(ByVal dir As String, ByVal fileExt As String)

        Try
            ' Display all files in a directory that match file type
            For Each fname As String In IO.Directory.GetFiles(dir)
                If fname.EndsWith(fileExt) Then
                    ListBoxControl1.Items.Add(My.Computer.FileSystem.GetName(fname))

                End If
            Next

            ' A recursive call for all the subdirectories in this directory.
            For Each subdir As String In IO.Directory.GetDirectories(dir)
                FileTypeFinder(subdir, fileExt)

            Next

        Catch ioex As System.UnauthorizedAccessException

        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString)

        End Try

    End Sub



Add items from Listbox1 to Listbox2: (This is where i need to be able to copy the selected file from it's current location to another folder.)

Private Sub Add_ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add_ButtonX1.Click

        Select Case ListBoxControl1.Items.Count
            Case 0
                MsgBox("There is nothing to add. Please browse for wav files.")
                Return
        End Select

        Try
            For Each str As String In Me.ListBoxControl1.SelectedItems
                Me.ListBoxControl2.Items.Add(str)

            Next

            For i As Integer = 0 To Me.ListBoxControl1.Items.Count - 1
                If Me.ListBoxControl1.SelectedIndex = i Then Me.ListBoxControl1.Items.RemoveAt(i)

            Next
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Sub

Many Thanks for any help.

Worf
Worf is offline   Reply With Quote
Old Jan 25th, 2009, 10:55 AM   #2
cdingSpree
hoßßy¦st C++ Þrogrammer
 
Join Date: Sep 2008
Posts: 800
Rep Power: 2 cdingSpree will become famous soon enough
Send a message via Skype™ to cdingSpree
Re: File search results to listbox help.

Quote:
Originally Posted by Worf
(This is where i need to be able to copy the selected file from it's current location to another folder.)
To copy and move a file, you could use:
VB.NET Syntax (Toggle Plain Text)
  1. System.IO.File.Copy("C:\file.txt", "C:\Users\newLocation.txt")
cdingSpree is offline   Reply With Quote
Old Jan 25th, 2009, 11:42 AM   #3
Worf
Newbie
 
Join Date: Jan 2009
Posts: 3
Rep Power: 0 Worf is on a distinguished road
Re: File search results to listbox help.

Hi cdingSpree

Thank you for your reply, before i can copy i need to be able to get the paths to each of the wav files in listbox1 and i am unable to work out how to do this.

I forgot to mention that i am a newbie.


Many Thanks
Worf is offline   Reply With Quote
Old Jan 30th, 2009, 8:16 AM   #4
subseven
Newbie
 
subseven's Avatar
 
Join Date: Jan 2009
Posts: 4
Rep Power: 0 subseven is on a distinguished road
Re: File search results to listbox help.

you can search by doing this
Imports System.IO
        listbox1.Items.AddRange(Directory.GetFiles("C:\", "*.wav", SearchOption.AllDirectories))
subseven is offline   Reply With Quote
Old Jan 30th, 2009, 8:32 AM   #5
Worf
Newbie
 
Join Date: Jan 2009
Posts: 3
Rep Power: 0 Worf is on a distinguished road
Re: File search results to listbox help.

Thanks all Sorted.
Worf is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save all search engine results urls in a text file abojan ASP 0 Dec 27th, 2006 8:33 AM
Basic File Search Program Twilight C++ 4 May 18th, 2006 3:36 PM
Assist in using cdl to add long file name to listbox -VB6 PrarieCat Visual Basic 0 Jan 5th, 2006 4:54 PM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC