Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async Task<int> CopyFilesToFolder(List<string> fileList,
- IProgress<int> progress, CancellationToken ct)
- {
- int totalCount = fileList.Count;
- int processCount = 0;
- foreach (var file in fileList)
- {
- string outputFile = Path.Combine(outputPath, file);
- await CopyFileAsync(file, outputFile);
- ct.ThrowIfCancellationRequested();
- processCount++;
- if (progress != null)
- {
- progress.Report(processCount * 100 / totalCount);
- }
- }
- return processCount;
- }
- private async Task CopyFileAsync(string sourcePath, string destinationPath)
- {
- using (Stream source = File.Open(sourcePath, FileMode.Open))
- {
- using (Stream destination = File.Create(destinationPath))
- {
- await source.CopyToAsync(destination);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement