-2

I'm developing an application with C# and I'm trying to compress a few files from different locations into a zipped file.

My problem is that I want to have a different structure within this zip file than the structure from the files.

Example:

FileA -> example.zip: \DirX\DirY
FileB -> example.zip: \DirX\DirZ
FileC -> example.zip: \DirW

I can preserve the folder structure but not change the "destination" path. Is there any external tool or programmatically within .Net to achieve this?

2 Answers2

2

did you try dotnetzip? - this is straightforward to do by just using a different path as name within the zip file using the AddEntry / AddFile methods.

Also see DotNetZip: Add Files to Dynamically Created Archive Directory

Community
  • 1
  • 1
BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
0

Robust solution - process zip file by entries and then extract/zip by using substituted path (which can be actual path of file, which you can put in the temporary folder before zipping or copy to needed location after extracting). The original path of files can be saved as text and then stored in the zip too (as it will anyway will have your designated structure, so you can reserve let's say "extract.txt" file to store original file location for extracting).

You can use libs (ICSharpCode.SharpZipLib or others) or go with .net framework 4.5 ZipArchive to perform basic operation with zip file itself.

Sinatr
  • 20,892
  • 15
  • 90
  • 319