I haven't play with ZipXStream and stuff but think how you would zip dirs/files using WinZip directly.
If you right-click on the directory and click winzip - the whole directory gets added to the zip file. And this is apparently what you got so far. So I think you now need to get inside the directory level then add those files.
A technique I often* use when zipping a folder recursively is the following:
This recursive call will build a full path for the ZIP entry names; for example "root/folder/subfolder/file.ext". That way, the full directory structure will remain intact in the ZIP file.
* Well actually once. I've simply put the code in a common utility class
sadanand munswamy wrote:Hi Rob,
Many thanks, for your prompt reply. But i am still not getting it worked as per my need,
Have been trying to tweak the API for a long time now. Can you please be a little more elaborate.
If I take your example of zipping folder C:\dir1\dir2\dir3 from this thread.
Assume that inside dir3 there are files file1 and file2, and sub directory dir4 with files file3 and file4.
I will then start by calling addToZip with a File object for C:\dir1\dir2\dir3 and a name of "".
The method will see that the file argument is a directory. It will then iterate over its sub folders and files (let's call these f). This will cause method calls addToZip(stream, f, "file1"), addToZip(stream, f, "file2") and addToZip(stream, f, "dir4").
The first two method calls will end because the file argument will not be a directory.
The third one will see that the file argument is a directory, and iterate over its contents again. It will now call addToZip(stream, f, "dir4/file3") and addToZip(stream, f, "dir4/file4").
As a result, the ZIP file will contain the following files: