|
-
Jun 11th, 2007, 02:39 AM
#1
Thread Starter
Addicted Member
[RESOLVED] My.Computer.FileSystem.CopyFile
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim result As DialogResult = Me.OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
For Each sFilePath As String In Me.OpenFileDialog1.FileNames
Me.ListBox1.Items.Add(sFilePath)
Next sFilePath
End If
End Sub
Private Function getFileName(ByVal sFilePath As String) As String
Dim iLenFilePath As Integer = sFilePath.Length
Dim iLastSlashPos As Integer = Strings.InStrRev(sFilePath, "textbox1.text")
Return Strings.Right(sFilePath, iLenFilePath - iLastSlashPos)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To Me.ListBox1.SelectedItems.Count - 1
Dim sFileName = getFileName(Me.ListBox1.SelectedItems.Item(i))
Try
My.Computer.FileSystem.CopyFile(Me.ListBox1.SelectedItems.Item(i), "textbox1.text" & sFileName)
MessageBox.Show("Copy was successfull for file " & sFileName)
Catch ex As Exception
MessageBox.Show("Error while copying file " & sFileName & vbNewLine & "Error message: " & ex.Message)
End Try
Next i
End Sub
hello this is my code
I can select files to A listbox, but now have to copy them one by one
to the directory I have choose in textbox1.text(the location), but how can I copie the selected files that in the listbox at the same time
so I have selected the files That I wont to copy
I say In the textbox1.text the location where to copy the files
end now I want to have i button to copy the selected files At one time In the directory where to copy can someon help me
Last edited by NeedHelp01; Jun 11th, 2007 at 02:42 AM.
-
Jun 11th, 2007, 02:46 AM
#2
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
I really don't understand what you mean by copying them at the same time.
try to do a basic copy paste of multiple files in the explorer, you can see that the files are created one by one to the destination.
I think that the way you are doing it now is the only of copying multiple files to the same destination. It allows to copy all the files with one click rather than the same number of clicks as there are files to be copied.
-
Jun 11th, 2007, 02:55 AM
#3
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
Ok
stap 1: seleced the files
stap 2: copy the selected files to de locations where to copy the selected files,the location can you give in textbox1.text.
stap to copy file.
If I copy the files, I can not open the openfile dialog again to copy notter files I must close the project en open the project again how to start the openfiledialog
how can I the start openfiledialog without starting entirely project again
-
Jun 11th, 2007, 02:57 AM
#4
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
drag a button open in your form and name it open dialog
vb Code:
private sub buttonDialog()
openFileDialog1.showDialog()
end sub
-
Jun 11th, 2007, 03:04 AM
#5
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
yes I thit that
okay I have done that but when I choose a file he don't set in de listbox how come??
-
Jun 11th, 2007, 03:06 AM
#6
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
you have to implement the code you used in the form1_load event.
Select the files
click the ok button in the openFileDialog
add the selected files to the listbox
-
Jun 11th, 2007, 03:10 AM
#7
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
oke thanx
how can I refresh the listbox.
When i select the files, I can not refresh the listbox to copy other files to a other location??
Last edited by NeedHelp01; Jun 11th, 2007 at 03:30 AM.
-
Jun 11th, 2007, 03:49 AM
#8
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
when I select a file to copy.
he copy the files to the same directory from where I copy the file
how to copy the files to a other directory
stap1 copy files from D:\templates
stap2 copy the selected to D:templates\C-drive
how can It that he don't copy the files to D:templates\C-drive
I have a textbox where I give the location where to copy but he don't do that
vb Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim result As DialogResult = Me.OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
For Each sFilePath As String In Me.OpenFileDialog1.FileNames
Me.ListBox1.Items.Add(sFilePath)
Next sFilePath
End If
End Sub
Private Function getFileName(ByVal sFilePath As String) As String
Dim iLenFilePath As Integer = sFilePath.Length
Dim iLastSlashPos As Integer = Strings.InStrRev(sFilePath, "\")
Return Strings.Right(sFilePath, iLenFilePath - iLastSlashPos)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To Me.ListBox1.SelectedItems.Count - 1
Dim sFileName = getFileName(Me.ListBox1.SelectedItems.Item(i))
Try
My.Computer.FileSystem.CopyFile(Me.ListBox1.SelectedItems.Item(i), "textbox1.text" & sFileName)
MessageBox.Show("Copy was successfull for file " & sFileName)
Catch ex As Exception
MessageBox.Show("Error while copying file " & sFileName & vbNewLine & "Error message: " & ex.Message)
End Try
Next i
End Sub
Private Sub cmdSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSelectFile.Click
Dim result As DialogResult
result = FolderBrowserDialog1.ShowDialog
If result = Windows.Forms.DialogResult.OK Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
-
Jun 11th, 2007, 04:01 AM
#9
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
vb Code:
My.Computer.FileSystem.CopyFile(Me.ListBox1.SelectedItems.Item(i), "textbox1.text" & sFileName)
what does this line do?
it saves the file (c:/mytest.txt) to the folder named textbox1.textmytest.txt
when you run the program, do you get the successful or unsuccessfull messagebox?
-
Jun 11th, 2007, 04:06 AM
#10
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
hey say copy file succesful messagebox
yess this is my big problem
it saves the file (c:/mytest.txt) to the folder named textbox1.textmytest.txt
but how else can I give the directory where to copy the file
because I have a brows button to say in textbox1.text the path of the where to copy the selected files how can I say in the listbox to read from textbox1.text??
-
Jun 11th, 2007, 04:08 AM
#11
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
i think
Code:
My.Computer.FileSystem.CopyFile(Me.ListBox1.SelectedItems.Item(i), "textbox1.text" & sFileName)
should be
Code:
My.Computer.FileSystem.CopyFile(Me.ListBox1.SelectedItems.Item(i), textbox1.text & sFileName)
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
-
Jun 11th, 2007, 04:10 AM
#12
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
remove the quotes around the textbox1.text and this will give you the value inside the textbox
vb Code:
My.Computer.FileSystem.CopyFile(Me.ListBox1.SelectedItems.Item(i), textbox1.text & "/" & sFileName)
-
Jun 11th, 2007, 04:14 AM
#13
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
yess it works but a nother problem how to refresh the listbox
when i start the project he keeps the selected files in the listbox
how to refresh the listbox to empty the listbox
-
Jun 11th, 2007, 04:27 AM
#14
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
-
Jun 11th, 2007, 04:33 AM
#15
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
how can I give in the form titelbar the command
that I have a option in the titelbar to clear the listbox
-
Jun 11th, 2007, 04:34 AM
#16
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
else I have a lot of buttons
I don't wont to have a lot of buttons an my form
-
Jun 11th, 2007, 04:46 AM
#17
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
the code that you are using in the form1_load event is exactly the same as the one you have under the openFiledailog button. this means that insted of having the same code twice, simulate the click of the openfiledialog in the load event.
then use this code to clear the listbox everytime you select some new files
vb Code:
Dim result As DialogResult = Me.OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
me.listbox1.items.clear
For Each sFilePath As String In Me.OpenFileDialog1.FileNames
Me.ListBox1.Items.Add(sFilePath)
Next sFilePath
End If
 Originally Posted by NeedHelp01
else I have a lot of buttons
I don't wont to have a lot of buttons an my form
this is not true because I only see 2 buttons and a listbox on the form.
on button to open the openfiledialog
1 button to copy the files and the listox
3 controls only
-
Jun 11th, 2007, 05:02 AM
#18
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
 Originally Posted by talkro
this is not true because I only see 2 buttons and a listbox on the form.
on button to open the openfiledialog
1 button to copy the files and the listox
3 controls only
yes that is true
my problem is solved as I can see
maby you can see more thinks that I can fixe??
maby de files I have selected In the openfiledialog
he set the files now in the listbox from the listbox I copy them to the directory I give IN THE TEXTBOX.
how can I automatic copy the files to the directory which I have indicated in the textbox
I do not want each time to say yes copy to
I want to have the listbox viseble on false
wath I have selected in the openfiledialog copy automatic to the directory
-
Jun 11th, 2007, 05:19 AM
#19
Fanatic Member
Re: My.Computer.FileSystem.CopyFile
you can only have a button and a textbox on your form called copy files. This button will open the openFileDialog. When the user clicks on ok, you loop through the selected files and use the instruction my.computer.copyfiles() to save them in the location specified in the textbox
-
Jun 11th, 2007, 05:24 AM
#20
Thread Starter
Addicted Member
Re: My.Computer.FileSystem.CopyFile
but how can I copy automatic the selected files in the listbox with out to say whit's files. I want to copy from the list box, how to select automatic the files that come in the listbox I don't have to see wath files I have selected in the openfiledialog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|