Advertisement
Guest User

Untitled

a guest
Sep 10th, 2014
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1.     async Task<int> CopyFilesToFolder(List<string> fileList,
  2.         IProgress<int> progress, CancellationToken ct)
  3.     {
  4.         int totalCount = fileList.Count;
  5.         int processCount = 0;
  6.  
  7.         foreach (var file in fileList)
  8.         {
  9.             string outputFile = Path.Combine(outputPath, file);
  10.  
  11.             await CopyFileAsync(file, outputFile);
  12.  
  13.             ct.ThrowIfCancellationRequested();
  14.             processCount++;
  15.             if (progress != null)
  16.             {
  17.                 progress.Report(processCount * 100 / totalCount);
  18.             }
  19.  
  20.         }
  21.  
  22.         return processCount;
  23.     }
  24.  
  25.  
  26.     private async Task CopyFileAsync(string sourcePath, string destinationPath)
  27.     {
  28.         using (Stream source = File.Open(sourcePath, FileMode.Open))
  29.         {
  30.             using (Stream destination = File.Create(destinationPath))
  31.             {
  32.                 await source.CopyToAsync(destination);
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement