Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,041 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!




Copy a selected file to multiple selected directories

 
Reply to this topicStart new topic

Copy a selected file to multiple selected directories

dandes
29 Feb, 2008 - 02:37 PM
Post #1

New D.I.C Head
*

Joined: 1 Feb, 2008
Posts: 4

I am very new to VB.net and anything I do know is self taught so please bear with me

I am trying to develop a program that will allow a user to select files using the open file dialog. The files will then be copied into multiple directories that the user selects from another open file dialog. All selections are listed in a list box. When the user hits the Go button the selected files are copied to all the selected directories.

At least that is my intent.

I have struggled with this and looked at a bunch of sample code and just cannot get it put together.

The code I have so far is:
vb

Imports System.IO



Dim File2Copy As String

Private Sub Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub

Private Sub File(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenFD.Multiselect = True

If OpenFD.ShowDialog = DialogResult.OK Then
For Each s As String In OpenFD.FileNames
ListBox2.Text &= s & Environment.NewLine
System.IO.Path.GetFileNameWithoutExtension(s)

'File.Copy(s, File2Copy & "\" & System.IO.Path.GetFileName(s))
Next
End If
End Sub

Private Sub Directories(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFD.Multiselect = True

If OpenFD.ShowDialog = DialogResult.OK Then
For Each s As String In OpenFD.FileNames
ListBox1.Text &= s & Environment.NewLine
System.IO.Path.GetFileNameWithoutExtension(s)
File.Copy(s, File2Copy & "\" & System.IO.Path.GetFileName(s))
Next
End If
End Sub

Private Sub Go(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

End Sub
End Class


This post has been edited by PsychoCoder: 29 Feb, 2008 - 02:52 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Copy A Selected File To Multiple Selected Directories
29 Feb, 2008 - 02:51 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Are you receiving any error message? If not, what is this code doing versus what you want it to do?
User is offlineProfile CardPM
+Quote Post

dandes
RE: Copy A Selected File To Multiple Selected Directories
29 Feb, 2008 - 03:07 PM
Post #3

New D.I.C Head
*

Joined: 1 Feb, 2008
Posts: 4

QUOTE(PsychoCoder @ 29 Feb, 2008 - 03:51 PM) *

Are you receiving any error message? If not, what is this code doing versus what you want it to do?





I am not getting an errors at all. Absolutly nothing happens other than being able to open the dialog.
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Copy A Selected File To Multiple Selected Directories
29 Feb, 2008 - 07:10 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
You never assign File2Copy a value, so the files created will be in your Bin directory. Give it a path to where you want the files created.

Also you need a String to hold the value that you get back from GetFileName method. Don't use the GetFileNameWithoutExtension method because you need the file extensions in order to save the file. Then uncomment and modify the File.Copy statement and modify it to use the filename and extension stored in result.

I'm not sure why you have two different buttons that are trying to do that same thing, but your Directories click event is using the same code to do the same thing, with the same problem.

Is there a reason that you have two buttons doing the same thing?

CODE
Private Sub File(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        OpenFD.Multiselect = True

        Dim result As String

        If OpenFD.ShowDialog = DialogResult.OK Then
            For Each s As String In OpenFD.FileNames
                ListBox2.Text &= s & Environment.NewLine

                result  = System.IO.Path.GetFileName(s)

                File.Copy(s, File2Copy & "\" & result)
            Next
        End If
    End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month