static void Main(string[] args) { Targeter target = new Targeter(); FileCopier copier = new FileCopier(); Console.WriteLine("Give target folder.."); string sourceFolder = Console.ReadLine(); Console.WriteLine("Give destination folder.."); string destinationFolder = Console.ReadLine(); //"C:\Users\Razvan\source\repos\TaskHomework\TaskHomework\Folder1" //"C:\Users\Razvan\source\repos\TaskHomework\TaskHomework\Folder2" Task copy = copier.ProcessWriteAsync(sourceFolder, destinationFolder); Task.Run(() => copy); Task.WaitAll(); }
private async Task MoveAsync(string sourceDirectory, string destinationDirectory) { Targeter targeter = new Targeter(); targeter.FolderFilesInformation(sourceDirectory); Parallel.ForEach(Directory.EnumerateFiles(sourceDirectory), async filename => { string sourceFileSHA = targeter.ComputeSHA(filename); Console.WriteLine($"Started the moving for file {filename}."); using (FileStream sourceStream = File.Open(filename, FileMode.Open)) { using (FileStream destinationStream = File.Create(destinationDirectory + filename.Substring(filename.LastIndexOf('\\')))) { Console.WriteLine($"Finished the moving for file {filename}."); targeter.FileDetails(filename); string destinationFileSHA = targeter.ComputeSHA(filename.Substring(filename.LastIndexOf('\\'))); targeter.VerifySHA(sourceFileSHA, destinationFileSHA); await sourceStream.CopyToAsync(destinationStream); } } }); Console.WriteLine("Finished. All files are now moved in the new folder."); targeter.FileRankings(destinationDirectory); }