user-0 提问: 如何使用zlib或者其他库编写一个程序实现目录的压缩

回复:
user: user-1
content: 你先用tar打包成一个文件，再用你的那个代码最这个打包后的tar文件进行压缩就可以了

user: user-0
content: 引用 2 楼 user-32 的回复:zlib里那个压缩函数会用之后，剩下的不是只要自己设计下文件结构了么 能给个思路吗？

user: user-0
content: 引用 4 楼 zhao4zhong1 的回复:WinExec("C:\\Program Files\\WinRAR\\rar.exe a d:\\mydir.rar -r d:\\mydir\\*.*",SW_HIDE); #include <memory.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>  #include <zlib.h> #include "GZIPFile.h"  #define BUFFERLEN 100   //zip文件打包 int G_gzfile(const char *inFile, const char *outFile) {     int fp; char buff[BUFFERLEN]; int len;     gzFile file;      if((fp=open(inFile,O_RDONLY))==0)//O_BINARY     {         printf("open打开%s文件错误!\n",inFile);         return -1;     }     file = gzopen(outFile, "wb");     if (file == NULL)  {         printf("gzopen打开%s文件错误!\n",outFile);         return -1;     } memset(buff,0,sizeof(buff));  len = read(fp,buff,sizeof(buff)); while(len  > 0) { gzwrite(file,buff,len); len = read(fp,buff,sizeof(buff)); }     gzclose(file); close(fp);     return 0; } //zip文件解包 int G_ungzfile(const char *inFile, const char *outFile) { gzFile file; char uncompr[BUFFERLEN]; int len; int count =0;   	FILE *fp_out;    	file = gzopen(inFile, "rb");   	if (file == NULL)    	{   	printf("gzopen打开%s文件错误!\n",inFile);     return -1;   	}     if((fp_out=fopen(outFile,"wb+"))==NULL)//O_BINARY     {         printf("fopen打开%s文件错误!\n",outFile);         return -1;     } len = gzread(file, uncompr, sizeof(uncompr));     while( len > 0 ) { int nLen = fwrite(uncompr,1,len,fp_out); if ( nLen!= len) { //printf("nLen = [%d], len= [%d]\n", nLen, len); printf("write写%s文件错误!\n",outFile); return -1; } len = gzread( file, uncompr, sizeof(uncompr));     }     gzclose(file); fclose(fp_out);     return 0; } 通过这个可以想到思路吗？请求支招

user: user-2
content: 直接调用现成压缩软件的命令行最方便。 非要看目录压缩解压的代码的话，参考Linux下tar的源代码。

user: user-0
content: 没思路，我手头上有的文件压缩代码拿出来   #include <memory.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>  #include <zlib.h> #include "GZIPFile.h"  #define BUFFERLEN 100   //zip文件打包 int G_gzfile(const char *inFile, const char *outFile) {     int fp; 		char buff[BUFFERLEN]; 		int len;     gzFile file;      if((fp=open(inFile,O_RDONLY))==0)//O_BINARY     {         printf("open打开%s文件错误!\n",inFile);         return -1;     }     file = gzopen(outFile, "wb");     if (file == NULL)  		{         printf("gzopen打开%s文件错误!\n",outFile);         return -1;     } 		memset(buff,0,sizeof(buff));  		len = read(fp,buff,sizeof(buff)); 		while(len  > 0) 		{ 			gzwrite(file,buff,len); 			len = read(fp,buff,sizeof(buff)); 		}     gzclose(file); 		close(fp);     return 0; } //zip文件解包 int G_ungzfile(const char *inFile, const char *outFile) { 		gzFile file; 		char uncompr[BUFFERLEN]; 		int len; 		int count =0;   	FILE *fp_out;    	file = gzopen(inFile, "rb");   	if (file == NULL)    	{   	printf("gzopen打开%s文件错误!\n",inFile);     return -1;   	}     if((fp_out=fopen(outFile,"wb+"))==NULL)//O_BINARY     {         printf("fopen打开%s文件错误!\n",outFile);         return -1;     } 		len = gzread(file, uncompr, sizeof(uncompr));     while( len > 0 ) 		{ 			int nLen = fwrite(uncompr,1,len,fp_out); 			if ( nLen!= len) 			{ 				//printf("nLen = [%d], len= [%d]\n", nLen, len); 				printf("write写%s文件错误!\n",outFile); 				return -1; 			} 		len = gzread( file, uncompr, sizeof(uncompr));     }     gzclose(file); 		fclose(fp_out);     return 0; } 怎么在这个上面更改，达到可以实现压缩目录

user: user-2
content: WinExec("C:\\Program Files\\WinRAR\\rar.exe a d:\\mydir.rar -r d:\\mydir\\*.*",SW_HIDE);

user: user-2
content: WinExec("C:\\Program Files\\WinRAR\\rar.exe a mydir.rar -r d:\\mydir\\*.*".SW_HIDE);

user: user-3
content: zlib里那个压缩函数会用之后，剩下的不是只要自己设计下文件结构了么

user: user-0
content: 顶起来。。。。