Results 1 to 6 of 6

Thread: [RESOLVED] [2008] Copy Multiple Files without a loop

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Resolved [RESOLVED] [2008] Copy Multiple Files without a loop

    Hi!!

    Is it possible to copy multiple files without having to make use of a loop.

    Right now the only way I know to copy multiple files is to loop through them like:
    vb.net Code:
    1. Dim Files As New List (Of String)
    2. Files.AddRange(OPD.FileNames)
    3. For a as Integer = 0 To Files.Count - 1
    4.      My.Computer.FileSystem.CopyFile(Files(a), "C:\APath\")
    5. Next

    Is there a way like:
    vb.net Code:
    1. Dim Files As New List (Of String)
    2. Files.AddRange(OPD.FileNames)
    3. My.Computer.FileSystem.CopyMultipleFile(Files, "C:\APath\")
    (OPD is an openfiledialog)
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2008] Copy Multiple Files without a loop

    You could use cmd.exe to do this
    Code:
            'copy all files from A Path to B Path
            Dim info As New ProcessStartInfo("cmd.exe", "/C copy C:\APath\* C:\BPath")
            info.UseShellExecute = False
            info.CreateNoWindow = True
    
            Dim proc As New Process
            proc.StartInfo = info
            proc.Start()
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Copy Multiple Files without a loop

    Why would you want to though? I dont think it'll be any more efficient, seeing as the harddrive can not read/write from more than one position at a time.
    I could be wrong though.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Copy Multiple Files without a loop

    You can do a CopyDirectory() otherwise you're in a loop. I don't see why a loop is a bad thing though. If the .Net Framework provided a way to copy multiple files I'm sure it would use a loop.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

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

    Re: [2008] Copy Multiple Files without a loop

    Given that OpenFileDialog.FileNames is a String array, what's the List(Of String) for? Why do you need to create a List to loop through when you've already got an array you can loop through?
    vb.net Code:
    1. For Each filePath As String In opd.FileNames
    2.     My.Computer.FileSystem.CopyFile(filePath, "C:\APath")
    3. Next
    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
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2008] Copy Multiple Files without a loop

    thks.
    jmcilhinney: very well noted! thks
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

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