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?
Printable View
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?
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/
It's not really about compression. I'd like to package 30 word docs into a single .zip file so I can email it.
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.
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.Quote:
Originally posted by GaPe
If it is not about compression than why did you post this thread here?
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.
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.
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.
zlib is freely available and quite well documented.
That looks like the perfect solution. Thank you. :)Quote:
Originally posted by Stoned_Coder
zlib is freely available and quite well documented.
I'm sure I'll post back with newbie questions. This is all quite new to me. :o
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...Quote:
Originally posted by Stoned_Coder
zlib is freely available and quite well documented.
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. :DCode:/Project Root
/Debug/
/src/
main.c
RptSendMail.dsw
etc...
Read the docs.Quote:
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. :D
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.Quote:
Originally posted by quzah
Read the docs.
Quzah.
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.
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.
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:
I'm getting an error when trying to compile. It cannot find the header files.Code:#include <stdio.h>
#include <src/ioapi.h>
#include <src/unzip.h>
#include <src/zconf.h>
#include <src/zip.h>
#include <src/zlib.h>
Code:Cannot open include file: 'src/ioapi.h': No such file or directory
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.
I added them in my MSVC++ include directory and they are seen. However, when I compile I get 57 errors in those header files.
Why wouldn't you keep the header files local to your project? If you package it up, won't you need to include those as well?
using libraries is usually simple.
1) ensure headers are where they should be. Thats in your include dir or a sub-dir of it.
2) either add the .lib to your project or add it in your libraries section of project options.
Thats normally enough. The header files declare functions that are implemented in the .lib and your compiler should be able to find the functions implementation now.
As for putting those headers in your source directory it is not necessary. The only headers in your source directory should be ones you have written yourself for your own classes usually.
What are the errors you are getting?
Have you tried adding the dll to the project too? you probably dont need to do that but it might do the trick.
Thanks for the explaination!
What I've currently done is create a lib directory in my project file structure (/projectRoot/lib/). In there I've added the .lib and .dll files from zlib. Then, I went into VC and did Project -> Add to Project -> Files and selected both of those files (.lib and .dll). I'm still getting the errors as mentioned above.
About the errors, they look like syntax errors in the header files themselves. Here are a few examples...
Code:Compiling...
main.c
c:\program files\microsoft visual studio\vc98\include\ioapi.h(34) : error C2143: syntax error : missing ')' before '*'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(34) : error C2143: syntax error : missing '{' before '*'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(34) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(34) : error C2061: syntax error : identifier 'OF'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(34) : error C2059: syntax error : ';'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(34) : error C2146: syntax error : missing ')' before identifier 'opaque'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(35) : error C2143: syntax error : missing ')' before '*'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(35) : error C2143: syntax error : missing '{' before '*'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(35) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(35) : error C2061: syntax error : identifier 'OF'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(35) : error C2059: syntax error : ';'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(35) : error C2146: syntax error : missing ')' before identifier 'opaque'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(36) : error C2143: syntax error : missing ')' before '*'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(36) : error C2143: syntax error : missing '{' before '*'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(36) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(36) : error C2061: syntax error : identifier 'OF'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(36) : error C2059: syntax error : ';'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(36) : error C2146: syntax error : missing ')' before identifier 'opaque'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(37) : error C2061: syntax error : identifier 'OF'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(37) : error C2059: syntax error : ';'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(37) : error C2146: syntax error : missing ')' before identifier 'opaque'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(38) : error C2061: syntax error : identifier 'OF'
c:\program files\microsoft visual studio\vc98\include\ioapi.h(38) : error C2059: syntax error : ';'
yep they certainly look like syntax errors. I thought you would be having linking errors. Id say you have 3 choices. Either try to fix the code yourself, or find a port of it for your specific compiler, or email the code authors to ask about the problems.
I think option 1 is def out. ;) I'm not sure what you mean by option 2. I'll probably end up going with option 3. I went to the zlib website, where you can download the source. In their FAQ, it gives you a site were you can get a precompiled windows dll. So I went ahead with that and in their package, you get the lib, dll, and h files. I'll probably email the guy giving out the windows dll first. Maybe I should try and compile the source myself. :dunno:Quote:
Originally posted by Stoned_Coder
yep they certainly look like syntax errors. I thought you would be having linking errors. Id say you have 3 choices. Either try to fix the code yourself, or find a port of it for your specific compiler, or email the code authors to ask about the problems.