code_junkie

Effective copying multiple files

Nov 11th, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. string[] files = Directory.GetFiles(rootFolder, "*.xml");
  2. foreach (string file in files)
  3. {
  4. string otherFile = Path.Combine(otherFolder, Path.GetFileName(file));
  5. File.Copy(file, otherFile);
  6. }
  7.  
  8. fsSource = New FileStream(backupPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None, 1024, FileOptions.WriteThrough)
  9. fsDest = New FileStream(restorationPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 1024, FileOptions.WriteThrough)
  10. TransferData(fsSource, fsDest, 1048576)
  11.  
  12. Private Sub TransferData(ByVal FromStream As IO.Stream, ByVal ToStream As IO.Stream, ByVal BufferSize As Integer)
  13. Dim buffer(BufferSize - 1) As Byte
  14.  
  15. Do While IsCancelled = False 'Do While True
  16. Dim bytesRead As Integer = FromStream.Read(buffer, 0, buffer.Length)
  17. If bytesRead = 0 Then Exit Do
  18. ToStream.Write(buffer, 0, bytesRead)
  19. sizeCopied += bytesRead
  20. Loop
  21. End Sub
Add Comment
Please, Sign In to add comment