Missing root folder as directory entry in results of MoveToNextEntry #205

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

Originally created by @KvanTTT on GitHub (Jul 5, 2017).

I use the following code for archive bypassing:

using (Stream stream = File.OpenRead(sourceArchiveFileName))
{
    using (IReader reader = ReaderFactory.Open(stream))
    {  
        while (reader.MoveToNextEntry())
        {
            string path = reader.Entry.Key;
            
            // Expected behavior
            // Create directory only for directory items
            if (entry.IsDirectory)
            {
                Directory.CreateDirectory(Path.Combine(destDir, path));
                continue;
            }
        
            // Actual workaround: extract directory path and create it for each file entry 
            Directory.CreateDirectory(
                Path.Combine(destDir, Path.GetDirectoryName(path)));
            
            // Write file item to stream
            using (var sourceFileStream = new FileStream(Path.Combine(destDir, path), FileMode.Create))
            {
                reader.WriteEntryTo(sourceFileStream);
            }
        }
    }
}

And get the following result items for attached test archive Folder.zip obtained from standard Windows zip utility (7z does not have such issue):

Actual result items

Folder/Folder2/
Folder/Folder2/text.txt
Folder/text.txt

But it should be

Expected result items

Folder/
Folder/Folder2/
Folder/Folder2/text.txt
Folder/text.txt
Originally created by @KvanTTT on GitHub (Jul 5, 2017). I use the following code for archive bypassing: ```CSharp using (Stream stream = File.OpenRead(sourceArchiveFileName)) { using (IReader reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { string path = reader.Entry.Key; // Expected behavior // Create directory only for directory items if (entry.IsDirectory) { Directory.CreateDirectory(Path.Combine(destDir, path)); continue; } // Actual workaround: extract directory path and create it for each file entry Directory.CreateDirectory( Path.Combine(destDir, Path.GetDirectoryName(path))); // Write file item to stream using (var sourceFileStream = new FileStream(Path.Combine(destDir, path), FileMode.Create)) { reader.WriteEntryTo(sourceFileStream); } } } } ``` And get the following result items for attached test archive [Folder.zip](https://github.com/adamhathcock/sharpcompress/files/1126090/Folder.zip) obtained from standard Windows zip utility (7z does not have such issue): ### Actual result items ``` Folder/Folder2/ Folder/Folder2/text.txt Folder/text.txt ``` But it should be ### Expected result items ``` Folder/ Folder/Folder2/ Folder/Folder2/text.txt Folder/text.txt ```
claunia added the questionnot bug labels 2026-01-29 22:08:19 +00:00
Author
Owner

@adamhathcock commented on GitHub (Jul 17, 2017):

I get the same actual result items. Whatever made that file did not actually put an entry in the zip archive for Folder/ In fact, having non-empty directories is redundant as you'd have to make them anyways to extract file

@adamhathcock commented on GitHub (Jul 17, 2017): I get the same actual result items. Whatever made that file did not actually put an entry in the zip archive for `Folder/` In fact, having non-empty directories is redundant as you'd have to make them anyways to extract file
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#205