Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to treat .zip files as directories in C#?

Tags:

c#

zip

I want to be able to be able to read files in zip files just as I would read files in a physical folder. How can I do this without having to extract the files?

like image 572
Suraj Avatar asked Apr 23 '10 19:04

Suraj


People also ask

Can ZIP files contain directories?

Note that the produced zip will contain the directory structure as well as the files. As peterph points out in his comment, this is usually seen as a good thing: extracting the zip will neatly store all the extracted files in one subdirectory.

How do I convert a ZIP file to a regular folder?

To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location. To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.

How do you treat a ZIP file?

Windows treats zip files just like folders. You can open a zip file, move files in and out of it, and open individual files just like you would if they were in a folder. Double-click the zip file.


2 Answers

There are some components out there that allow you to view the contents of a .zip file from your .NET application:

  • http://www.icsharpcode.net/opensource/sharpziplib/ - (free open source)
  • http://xceed.com/Zip_Net_Intro.html - (commercial)

I've used the #ziplib before and it worked fine for my purposes which weren't too extensive.

like image 99
dana Avatar answered Sep 27 '22 16:09

dana


I recently opened sourced my Platform.VirtualFileSystem C# library.

https://github.com/platformdotnet/Platform.VirtualFileSystem https://github.com/platformdotnet/Platform.VirtualFileSystem/wiki

You can read zip files like this:

var directory = FileSystemManager.Default.ResolveDirectory("zip://[file:///c:/test.zip]/");
directory.GetFiles().ForEach(Console.WriteLine);

It's available from NuGet: http://nuget.org/packages/Platform.VirtualFileSystem.Providers.Zip/

like image 23
tumtumtum Avatar answered Sep 27 '22 16:09

tumtumtum