Thread: Zipping files

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    Zipping files

    I'm trying to zip up all of the files in a certain directory. Does C have any functions that can do this? If not, where can I find some?

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    No, C has no datacompression function, if that is what you are looking for. Here you can find info on datacompression:
    http://www.data-compression.com/

  3. #3
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    It's not really about compression. I'd like to package 30 word docs into a single .zip file so I can email it.

  4. #4
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    If it is not about compression than why did you post this thread here?

    If you want to compress 30 word documents use Total Commander, WinZIP or use command line zip program.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #5
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by GaPe
    If it is not about compression than why did you post this thread here?
    Because I'm trying to do it programatically in C. I'm writing a script that will run each morning on a reporting server. It will zip up the files in a directory and email that zip file out each morning. It is larger scale than this, because there are 20+ folders, but I can easily expand this once I get one folder going.

    BTW, I've already done it in Java. But I'd like to replicate it with C so I can learn about C. Java has a class for this in the SDK.

  6. #6
    Registered User The Junglist's Avatar
    Join Date
    Nov 2002
    Posts
    42
    Here's a task for you :

    Write a program to merge a set of files into one file, then it must be able to split that file into the original files. The file names and file sizes can be stored in a text file.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    If you already have the zip program installed (say Winzip, for example), maybe you'll get away with simply invoking it from your program in the same way you would do so on the command line.

    Check out these which tell you how to spawn child processes.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    zlib is freely available and quite well documented.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by Stoned_Coder
    zlib is freely available and quite well documented.
    That looks like the perfect solution. Thank you.

    I'm sure I'll post back with newbie questions. This is all quite new to me.

  10. #10
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by Stoned_Coder
    zlib is freely available and quite well documented.
    Ok, I've downloaded the dll for zlib. It has some header files, a dll file, and a lib file. In my project (MSVC++ 6), my project structure looks like this...

    Code:
    /Project Root
      /Debug/
      /src/
        main.c
      RptSendMail.dsw
      etc...
    How do I import the zlib library so I can use it? Do I need to import all of the given files or only the header and dll files? Where do I copy the files to? Thanks in advance. I'm a newb.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by CompiledMonkey
    How do I import the zlib library so I can use it? Do I need to import all of the given files or only the header and dll files? Where do I copy the files to? Thanks in advance. I'm a newb.
    Read the docs.

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by quzah
    Read the docs.

    Quzah.
    I have been, that's why I waited so long to ask the question. This is also a MSVC++ 6.0 question, I'm curious as to what is considered "best practice" when dealing with header files and importing dlls. Also, overall file structure of applications.

    This (http://www.gzip.org/zlib/manual.html) helps a great deal in what the functions do and how to use them, but it doesn't talk about making them accessable to your app. It assumes you've already got access to them.

  13. #13
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    include the headers in the source file you use zlib funcs in.
    either add the .lib to your project or surf thru the project options to where additional libraries can be specified and add the .lib to the list. This will give you static linkage of the zlib code.
    The dll is for dynamic linking zlib code and i think can probably be ignored for now.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  14. #14
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Ok, I went to Project -> Add to Project -> Files and added the zlib.lib file. My source file (main.c) and all of my header files are in the /rootDirOfProject/src/ directory. My main.c file includes looks like this:

    Code:
    #include <stdio.h>
    #include <src/ioapi.h>
    #include <src/unzip.h>
    #include <src/zconf.h>
    #include <src/zip.h>
    #include <src/zlib.h>
    I'm getting an error when trying to compile. It cannot find the header files.

    Code:
    Cannot open include file: 'src/ioapi.h': No such file or directory

  15. #15
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    you should move the headers to a subdirectory of your compilers include directory.Then include them as <suddirname/headername.h> and all should be well.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM