Copying multiple files ( help )

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
17 posts Page 1 of 2
Contributors
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Copying multiple files ( help )
CodenBoy
Hello all, i just need little help and hope someone will help me :)

I know how to copy a single file to another location like this:
Code: Select all
my.computer.filesystem.copyfile("file location", "new folder location")
Ok, now what about if i wanted to copy ( Multiple ) files together?
If I had a Listbox with files locations like this
C:/file.exe
C:/text.txt
C:/pic.jpg
I want to copy them all to the new location how?

Thanks
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Edit:
I also want to have a progress bar, which moves to 100% when copying the files :)
thannks!
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Copying multiple files ( help )
Bogoh67
I tried this and it seems to work
Code: Select all
Imports System.IO
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ProgressBar1.Maximum = ListBox1.Items.Count
        For i As Integer = 0 To ListBox1.Items.Count - 1
            Dim thestrings() As String = ListBox1.Items(i).ToString.Split("\")
            Dim filename As String = thestrings(thestrings.Count - 1)
            FileCopy(ListBox1.Items(i), "C:\Test\" & filename)
            ProgressBar1.Value += i
        Next
    End Sub
End Class
these are the items in my listbox
C:\Users\josh\Users.txt
C:\Users\josh\Text.txt
C:\Users\josh\Mail.txt

And this is what the program looks like
Image

Hope it works for you :)
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Thanks for the help i will try this now and tell you if it worked or not :)

Thanks hehaho;
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

It tells me count is not a member of system.array
help please
in this code
Code: Select all
(thestrings.Count
plees help

EDIT: And I wanted it to paste the files? will this paste files? i mean copy and paste like moving file.

Thanks
Last edited by CodenBoy on Sun Jul 15, 2012 5:30 pm, edited 1 time in total.
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Copying multiple files ( help )
Bogoh67
maybe try changing it to thestrings.length
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Actually thanks but im so sorry idk what i wanted..
i just wanted to move multiple files from listbox but its like copy + paste

it keeps the file just copy, paste it in other directory
:o can u give me this codes :o
Bogoh7 if you got skype tell me so we can talk fast

Thaanks
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Copying multiple files ( help )
comathi
Wait, are you saying you want it to copy/paste the file, or move it entirely?
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Sorry for being noob but thanks for bogoh7 and what i want is

Im making a program in vb 2010 express and what i want is i want to make a backup of a file to another location. so it will keep the file but just Copy,paste it to another location.

Im using a Listbox ( with file names in lines ) and i want progress bar to move while im copying the files or backing up.

Thanks ( sorry for my bad english ) loove;
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Copying multiple files ( help )
Bogoh67
Do you mean hotkeys copy and paste? if you want this you can use
Code: Select all
My.Computer.clipboard
If you want program copy & paste this is probably what you should use
It does copy files from one place to another, but the files have to already exist.

by the way i made some slight code changes
Code: Select all
  ProgressBar1.Maximum = ListBox1.Items.Count
        For i As Integer = 0 To ListBox1.Items.Count - 1
            Dim thestrings() As String = ListBox1.Items(i).ToString.Split("\")
            Dim filename As String = thestrings(thestrings.Length - 1)
            FileCopy(ListBox1.Items(i), "C:\Test\" & filename)
            ProgressBar1.Value = i + 1
        Next
        MsgBox("File Completed Copying", MsgBoxStyle.Information, "Done!")
if this isn't what you mean, examples?


Unfortunantly i got rid of my skype account for i do not use it anymore
17 posts Page 1 of 2
Return to “Coding Help & Support”