• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to zip the contents inside a directory

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Mohnish Parmar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would get rid of your compressFiles method and replace lines 17 - 21 with
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic