VS 2010 Copy File/directory using Buffer?-VBForums
Results 1 to 5 of 5

Thread: Copy File/directory using Buffer?

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Thumbs down Copy File/directory using Buffer?

    Can anybody please explain to me what this code will do to the copy?
    vb Code:
    1. Using source As New IO.FileStream("source path here", IO.FileMode.Open)
    2.     Using target As New IO.FileStream("destination path here", IO.FileMode.Create)
    3.         Const BUFFER_SIZE As Integer = 1024
    4.         Dim buffer(BUFFER_SIZE - 1) As Byte
    5.         Dim bytesRead As Integer = source.Read(buffer, 0, BUFFER_SIZE)
    6.  
    7.         While bytesRead > 0
    8.             target.Write(buffer, 0, bytesRead)
    9.             bytesRead = source.Read(buffer, 0, BUFFER_SIZE)
    10.         End While
    11.  
    12.         target.Close()
    13.     End Using
    14.  
    15.     source.Close()
    16. End Using

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Copy File/directory using Buffer?

    Without trying it, it looks like it copies data in chunks of 1024 bytes from one file into another. I could not believe that this is faster than a standard copy, so unsure of its benefit.

  3. #3

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Copy File/directory using Buffer?

    Is there any way to do a copy, in vb.net, of files and folders FASTER than windows explorer?

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Copy File/directory using Buffer?

    I would hope not, or windows did not do a very good job! Seroiusly, I have never tested it, there could be faster methods which skip the feedback that explorer gives you, surely at a lower level then .Net.

    There are ways to copy files for backup/mirror reasons which use techniques of only copying what is needed (ie robocopy). Depends what you are trying to achive.

  5. #5

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Copy File/directory using Buffer?

    Quote Originally Posted by Grimfort View Post
    Depends what you are trying to achive.
    I want a quick backup of the system, but I also want the user to be in total control ie. being able to pause the backup/copy at any moment and continue at a later stage (The backup kills the system resources while running).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.