mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
Create tar.gz in source directory? #375
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DSR-Labs on GitHub (Sep 15, 2019).
Hey, is there a way to create the tar.gz archive in the same directory as the source?
(Creating the archive in another directory works.)
This is my code
private void TarNameBtn_Click (object sender, EventArgs e) { using (Stream stream = File.OpenWrite (savePluginPathTxtBox.Text + @ "\" + tarNameTxtBox.Text)) using (var writer = WriterFactory.Open (stream, ArchiveType.Tar, CompressionType.GZip)) { writer.WriteAll (rootPathTxtBox.Text, "*", SearchOption.AllDirectories); } }As soon as I try to create the archive in the same folder where the archived files are, I get the following error:
System.IO.IOException: 'The process can not access the file' C: \ Users \ ktown \ Desktop \ test.tar.gz 'because it is being used by another process.'@adamhathcock commented on GitHub (Sep 17, 2019):
You should scan the directory hierarchy and buffer it into a list before creating the archive and adding files.
Your File.OpenWrite will create a file instantly and therefore show up in any scanning of the file tree.