aspose file tools*
The moose likes Java in General and the fly likes How to zip the contents inside a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to zip the contents inside a directory" Watch "How to zip the contents inside a directory" New topic
Author

How to zip the contents inside a directory

Mohnish Parmar
Greenhorn

Joined: Jun 06, 2012
Posts: 2
I want to make a zip file of all contents inside a directory including subfolders & files,
I have a directory called Documents, in my code Document directory gets included in zip file, but I want only the contents within the Document directory
i.e folder1,folder2,folder3, file.txt
it should exclude Document directory in zip file, but all the contents(folders & files) within it, should be present
Please Help.

The directory structure is:

Document/
>folder1 ( Document/folder1 )
>file1.txt ( Document/folder1/file1.txt )
folder2 ( Document/folder2 )
>file2.txt ( Document/folder2/file2.txt )
folder3 ( Document/folder3 )
>file3.txt ( Document/folder3/file3.txt )
file.txt ( Document/file.txt )

Code:


Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
The Document directory is being included because you are adding it to listFiles on line 19. Instead you should be adding all the files and directories in Documents at this point.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
And welcome to the Ranch
Mohnish Parmar
Greenhorn

Joined: Jun 06, 2012
Posts: 2
How to add only the contents within directory in line 16 if possible
or is the way to remove "Document/" or "Document"in addFolderToZip method
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
I would get rid of your compressFiles method and replace lines 17 - 21 with
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to zip the contents inside a directory