public static async Task ExtractToFileAsync(this ZipArchiveEntry source, string destinationFileName, bool overwrite, CancellationToken cancellationToken = default, bool deleteAtCancellation = false) { try { await Task.Run(() => source.ExtractToFile(destinationFileName, overwrite), cancellationToken); } catch { if (deleteAtCancellation) { await FileAsync.TryAndRetryDeleteAsync(destinationFileName); } } }
public static async Task CopyAsync(string sourceDirectoryName, string destDirectoryName, bool overwrite = false, CancellationToken cancellationToken = default) { foreach (string dir in Directory.EnumerateDirectories(sourceDirectoryName)) { string postDir = Path.Combine(destDirectoryName, dir.Substring(sourceDirectoryName.Length + 1)); if (!Directory.Exists(postDir)) { Directory.CreateDirectory(postDir); } await CopyAsync(dir, postDir, overwrite, cancellationToken); } foreach (string file in Directory.EnumerateFiles(sourceDirectoryName)) { await FileAsync.CopyAsync(file, Path.Combine(destDirectoryName, Path.GetFileName(file)), overwrite, cancellationToken); } }