Click here to Skip to main content
15,888,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to zip a folder and its contents. Using
VB
ZipFile.CreateFromDirectory("source", "destination.zip")
zips the contents but not the containing directory.
How can I achieve this? Note: I don't want to zip all the folders where the source folder is.
For example...
In .minecraft/saves, I want to backup "World_A" including the folder, so that when opening the zip file with an archiver such as 7Zip or WinRAR, you first see the folder still containing the "World" data.

What I have tried:

Nothing I have searched on Google and various programming sites such as this one even mentions this issue.
If I try adding the directory name to the zipfile name, it gives a file not found error.
Posted
Updated 9-Jun-21 15:25pm

1 solution

Use the includeBaseDirectory option.
Quote:
includeBaseDirectory Boolean
true to include the directory name from sourceDirectoryName at the root of the archive;
false to include only the contents of the directory.

ZipFile.CreateFromDirectory Method (System.IO.Compression) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900