Really new with Go, trying to create a function that will grab a list of files and zip them up. Googled for a while today, i can easily archive files, but it also creates a folder inside the archive (which, for stupid reasons i don’t want to get into, won’t work). I basically need to take all the files in a directory, zip them with no folder structure, and that’s it. Here is kinda what i’m working with:
Notice how I improved error handling: you didn’t catch the error from filepath.Walk and “defer Close()” also makes the error (which might happen when you actually write the buffered file to disk) disappear. To fix that, I just used Flush().
Finally, please decorate your errors. Instead of returning err, return fmt.Errorf("could not <write what you are trying to do>: %v", err) (for example, ‘create zip header’, ‘open file to include in archive’, ‘copy file into archive’).
Personal note: I hate zip files that don’t create a folder.
I will try this out in a bit…but yeah man, me too. The requirements gathering stated that the consumption of this zip couldn’t handle a folder…like what?