Extract specific folder #488

Closed
opened 2026-01-29 22:12:51 +00:00 by claunia · 2 comments
Owner

Originally created by @bsuschi on GitHub (Jan 16, 2022).

Hello,
I need a little bit help for a problem I have. I can't solve it myself.

How can I check for a specific folder in a compression file and than extract only this folder if it present?
Is there a easy way to do this?

I check all directory entrys in a file, but when I extract it, there is nothing in my output folder.

using (var archive = ArchiveFactory.Open(compressedFile))
{
   foreach (var entry in archive.Entries)
   {
      if (entry.IsDirectory)
      {
         if (entry.ToString() == "{my searched folder}")
         {
            entry.WriteToDirectory(tempFolder, new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
         }
      }
   }
}                   

Thanks a lot
Uschi

Originally created by @bsuschi on GitHub (Jan 16, 2022). Hello, I need a little bit help for a problem I have. I can't solve it myself. How can I check for a specific folder in a compression file and than extract only this folder if it present? Is there a easy way to do this? I check all directory entrys in a file, but when I extract it, there is nothing in my output folder. ``` using (var archive = ArchiveFactory.Open(compressedFile)) { foreach (var entry in archive.Entries) { if (entry.IsDirectory) { if (entry.ToString() == "{my searched folder}") { entry.WriteToDirectory(tempFolder, new ExtractionOptions { ExtractFullPath = true, Overwrite = true }); } } } } ``` Thanks a lot Uschi
Author
Owner

@adamhathcock commented on GitHub (Jan 17, 2022):

folders don't really exist in archives. Files have "keys" which might have a path in it. Folder entries are essentially empty placeholders.

What you should do is look at all the keys for in your entries to see if they have the name as a substring. I usually always ignore directory entries.

@adamhathcock commented on GitHub (Jan 17, 2022): folders don't really exist in archives. Files have "keys" which might have a path in it. Folder entries are essentially empty placeholders. What you should do is look at all the keys for in your entries to see if they have the name as a substring. I usually always ignore directory entries.
Author
Owner

@bsuschi commented on GitHub (Jan 17, 2022):

Hello and thank you for your quick reply.

I have already guessed that it is the only way.
I had hoped that there is still a function to extract specific folders.

Thank you very much for everything. Great work

@bsuschi commented on GitHub (Jan 17, 2022): Hello and thank you for your quick reply. I have already guessed that it is the only way. I had hoped that there is still a function to extract specific folders. Thank you very much for everything. Great work
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#488