Results 1 to 6 of 6

Thread: Get directory size after compression

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Get directory size after compression

    Hello,
    I have a little trouble. I have to zip a directory, so far, things are going pretty well, he zipped the directory. However, I get the directory size before compression zip the directory size after compression zip, and then the compression ratio. How can I do to obtain these values?
    Here is my code:
    Code:
    / / Create the z with the folder name
    z = new ZipOutputStream(new FileOutputStream(folder.getName() + ". z"));
    / / Set the compression mode
    z.setMethod(ZipOutputStream.Deflated);
    / / Set the compression level = BEST
    z.setlevel(9);
     
    / / It defines a directory path with the "File"
    File directory = new File(folder.getPath());
     
    / / We archive all files (recursive) files and
    zpeRepertoire(directory, z);
     
    / / We close the z
    z.close();
    Can you help me with this.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Get directory size after compression

    Hello,
    I think you can get better than before the compression results are based on coarse heuristics that are more or less reliable. The only way to get the compressed size of a file is to compress it. Knowing that each algorithm compression has its weaknesses and strengths, and each type of file is not compressed in the same way.

  3. #3
    Join Date
    Dec 2009
    Posts
    263

    Re: Get directory size after compression

    Hello,
    Ok but how to get the compressed size? I have a compressed zip file, I do something like this, here is a part of my code
    Code:
    File fl = (File) zip;
    longtaille = fl.length();
    I have included these in my code, if you have any other alternative to this then you can please post.

  4. #4
    Join Date
    Dec 2009
    Posts
    213

    Re: Get directory size after compression

    Hello,
    Even I was trying the same. I had also included the following lines in my code. But the compiler rejects the following cast
    Code:
    File file = (File) zip;
    Apparently, you can not cast a ZipOutputStream in File. I hope I am correct. If I am not then please guide me with the correct use of it. And even if you have an sample code for this, it will be great.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Get directory size after compression

    Hi,
    Normal since zip is not a File object (or a derived object)
    Simply retrieve the File directly like this, just have a look at it
    Code:
    File f = new File(folder.getName() + ". zip");
    hope the above line will help you, I will recommend you to try it at-least once and then compile your program and if you get an error then please post here.

  6. #6
    Join Date
    Dec 2009
    Posts
    296

    Re: Get directory size after compression

    Hello,
    I also seek such information for the size of the zip is settled, but to know the size of the file before, there is nothing? Because I basically want to know if there is enough room on my hard to zip up my repertoire. But why I must know the size of this folder? I think i am confused with the concept of the following.

Similar Threads

  1. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  2. Command to find size of a directory
    By ThunDer_22 in forum Software Development
    Replies: 2
    Last Post: 17-06-2009, 02:14 PM
  3. Replies: 4
    Last Post: 01-10-2008, 06:41 PM
  4. Replies: 1
    Last Post: 24-04-2007, 03:14 PM
  5. Replies: 3
    Last Post: 18-04-2007, 04:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,058,349.51920 seconds with 17 queries