Create tar.gz in source directory? #375

Open
opened 2026-01-29 22:10:55 +00:00 by claunia · 1 comment
Owner

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.'

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.'`
claunia added the question label 2026-01-29 22:10:55 +00:00
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#375