I want to zip some directory inside content into zip file
e.g. assume i’ve this directory structure
dir1
file1.html
file2.go
No
Assuming you are calling your function as follows:
Zipit("dir1/", "dir1.zip")
All you need to do is remove the baseDir
that is being added to the filename inside the archive.
You currently have the following code:
if baseDir != "" {
header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source))
}
baseDir
here is dir1
.
Simply omit the baseDir
(but to keep trimming the prefix):
header.Name = strings.TrimPrefix(path, source)
This is very similar to Unzip artifacts with different name where all you need to do is modify header.Name
as you see fit. It sounds like you need to examine the various filepath
functions to see how they can help you.