C语言基于窗体命令行打包,解包和浏览程序
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<io.h>
#include<iostream>
#include<string>
int count=0;
char path[50];
struct Note *next;
}Note,*Lnote;
char name[20];
unsigned int size;
}Node,*List;
List creat(void);
void add(List *head,char *Tname,int Tsize);
void bwrite(char *fn);
void file_in(char *Path_r,char *Path_w);
void unzip(char *Path_file,char *Path_out);
void lookthepack(char *path);
Lnote Tcreat(void);
void Tadd(Lnote *Thead,char *Path);
void zip(char *ar1,char *ar2);
void lookthepack(char *path){
int i,j;
Node p;
FILE *fp;
if((fp=fopen(path,"rb"))==NULL){
printf("Can't open %s\n",path);
exit(1);
}
fseek(fp,0L,SEEK_SET);
rewind(fp);
fread(&j,sizeof(j),1,fp);
printf("打包文件总数为: %d\n",j);
for(i=0;i<j;i++){
fread(&p,sizeof(p),1,fp);
printf("%s\n",p.name);
}
}
void zip(char *ar1,char *ar2){
char check;
int l;
List head=creat();
Lnote Thead=Tcreat();
long Handle;
struct _finddata_t FileInfo;
l=strlen(ar1);
for(;l>0;l--){
if(ar1[l-1]=='\\'){
check=ar1[l];
break;}
}
if(check!='*')
strcat(ar1,"\\*.*");
if((Handle=_findfirst(ar1,&FileInfo))==-1){
/* 以下为路径不包括通配符情况*/
printf("路径不存在!\n");
exit(0);
}
else{
do{
if (!(strcmp(FileInfo.name, "..")&&strcmp(FileInfo.name,"."))){
continue;
}
char path_a[40];
/* 以下旨在获取除去通配符后的文件路径 */
int str_leng,t;
strcpy(path_a,ar1);
str_leng=strlen(path_a);
for(t= str_leng+1;;t--)
{if(path_a[t-1]=='\\'){
path_a[t]='\0';
break;}
else
path_a[t]='0';
}
char Tname[20];
strcpy(Tname,FileInfo.name);
strcat(path_a,Tname); //获取绝对路径
Tadd(&Thead,path_a);
add(&head,FileInfo.name,FileInfo.size);
count++;
}while(_findnext(Handle,&FileInfo)==0);
_findclose(Handle);
FILE *fp_stu,*fp_txt;
if((fp_stu=fopen(ar2,"ab+"))==NULL){
printf("Can't open++++ %s\n",ar2);
exit(1);
}
else{
rewind(fp_stu);
fwrite(&count,sizeof(count),1,fp_stu); //记录文件总个数为int型,并放在打包文件头
while(op!=NULL){
fwrite(op,sizeof(*op),1,fp_stu);
op=op->next;
}
fclose(fp_stu);
}
Note *pt;
pt=Thead->next;
while(pt!=NULL){
file_in(pt->path,ar2); //文件读取及写入
pt=pt->next;
}
}
}
void unzip(char *Path_file,char *Path_out){
FILE *fp1,*fp2,*fp3;
char ch;
int num,m=0;
Node p;
if((fp1=fopen(Path_file,"rb"))==NULL){
printf("Can't open %s\n",Path_file);
exit(1);
}
else if((fp2=fopen(Path_file,"rb"))==NULL){
printf("Can't open %s\n",Path_file);
exit(1);
}
else{
fseek(fp1,0L,SEEK_SET);
fseek(fp2,0L,SEEK_SET);
rewind(fp1);
rewind(fp1);
fread(&num,sizeof(num),1,fp1);
printf("The file-count is : %d\n",num);
fseek(fp2,sizeof(int),SEEK_SET);
fseek(fp2,sizeof(p)*num,SEEK_CUR);
do { m++;
fread(&p,sizeof(p),1,fp1);
char fullpath_out[40];
char name[20];
int i=0;
strcpy(name,p.name);
strcpy(fullpath_out,Path_out);
strcat(fullpath_out,name);
if((fp3=fopen(fullpath_out,"ab+"))==NULL){
printf("Can't open %s \n",fullpath_out);
exit(1);
}
else{
for(i=0;i<p.size;i+=(sizeof(char))){
fread(&ch,sizeof(ch),1,fp2);
fwrite(&ch,sizeof(ch),1,fp3);
}
}
}while(m<num);
fclose(fp1);
fclose(fp2);
fclose(fp3);
}
}
void file_in(char *Path_r,char *Path_w){
FILE *fpr,*fpw;
char ch;
if((fpr=fopen(Path_r,"rb"))==NULL){
printf("Can't open 文件路径 %s\n",Path_r);
exit(1);
}
if((fpw=fopen(Path_w,"ab+"))==NULL){
printf("Can't open 打包指向路径 %s\n",Path_w);
exit(1);
}
fseek(fpw,0L,SEEK_END);
while ((ch=fgetc(fpr))!=EOF)
fputc(ch,fpw);
fclose(fpr);
fclose(fpw);
}
Lnote Tcreat(void){
Lnote Thead=(Lnote)malloc(sizeof(Note));
Thead->next=NULL;
return Thead;
}
void Tadd(Lnote *Thead,char *Path){
Note *s,*r;
r=*Thead;
while(r->next!=NULL){
r=r->next;
}
s=(Lnote)malloc(sizeof(Note));
strcpy(s->path,Path);
r->next=s;
s->next=NULL;
}
List creat(void){
List head=(List)malloc(sizeof(Node));
head->next=NULL;
return head;
}
void add(List *head,char *Tname,int Tsize){
int i=0;
Node *s,*r;
r=*head;
while(r->next!=NULL){
r=r->next;
}
s=(List)malloc(sizeof(Node));
strcpy(s->name,Tname);
s->size=Tsize;
r->next=s;
s->next=NULL;
}
if(argc>=1){
if(strcmp(argv[1],"help")==0){
printf("此程序命令行参数如下: \n");
printf("命令总数为 %d \n",argc+1);
for(int i=0;i<argc;i++)
printf("%s %d\n",argv[i],i);
}
}
char a[20],b[5];
for(int i=0;i<2;i++){
b[i]=argv[1][i];
}
b[2]='\0';
if(strcmp(argv[1],"-l")==0){
lookthepack(argv[2]);
}
/* 以下对应于argv[1]为‘-u’时,表示解压 */
else if(strcmp(b,"-u")==0){
printf("sasda\n");
unzip(argv[2],argv[3]);
}
else {
zip(argv[1],argv[2]);
}
return 0;
/*事例命令如下*/
//E:\打包事例\test.exe E:\打包事例\Thepack\*.* E:\打包事例\
//E:\打包事例\test.exe -l E:\打包事例\testqq.txt
//E:\打包事例\test.exe -u E:\打包事例\testqq.txt E:\打包事例\zxcv\
}
C语言基于窗体命令行打包,解包和浏览程序的更多相关文章
- 7个基于Linux命令行的文件下载和网站浏览工具
7个基于Linux命令行的文件下载和网站浏览工具 时间:2015-06-01 09:36来源:linux.cn 编辑:linux.cn 点击: 2282 次 Linux命令行是GNU/Linux中最神 ...
- 使用命令行打包 nuget 包
对于那些不打算涉及这么复杂而又想制作自己的 nuget 包的园友们,我是推荐使用 Nuget Package Explorer 来制作的.关于这个图形化的 nuget 包管理软件的使用,博客园内有相关 ...
- 5个基于Linux命令行的文件下载和网站浏览工具
导读 命令行是GNU/Linux中最神奇迷人的部分,它是非常强大的工具;命令行本身功能多样,多种内建或者第三方的命令行应用使得Linux变得更加健壮和强大.Linux Shell支持多种不同类型的网络 ...
- 命令行打包war包
输入jar -cvf 包名.war 目录/*
- 基于RTP的H264视频数据打包解包类
from:http://blog.csdn.net/dengzikun/article/details/5807694 最近考虑使用RTP替换原有的高清视频传输协议,遂上网查找有关H264视频RTP打 ...
- [Android] 基于 Linux 命令行构建 Android 应用(七):自动化构建
本章将演示如何基于 Linux 命令行构建 Android 应用,在开始本章之前,希望你已经阅读之前几章内容. 本文环境为 RHEL Sandiego 32-bits,要基于 Linux CLI 构建 ...
- [转载]OpenSSL中文手册之命令行详解(未完待续)
声明:OpenSSL之命令行详解是根据卢队长发布在https://blog.csdn.net/as3luyuan123/article/details/16105475的系列文章整理修改而成,我自己 ...
- 7Z命令行详解
7z.exe在CMD窗口的使用说明如下: 7-Zip (A) 4.57 Copyright (c) 1999-2007 Igor Pavlov 2007-12-06 Usage: 7za <co ...
- mac下使用命令行打包出现bash gradle command not found的解决方案
命令行打包的时候出现 bash gradle command not found这个问题,主要是因为gradle环境丢失.需要重新配置gradle的环境变量. 1. gradle路径的查找 然后gra ...
随机推荐
- 虚拟化(三) -vsphere套件的安装注意及使用
https://www.cnblogs.com/zhrngM/p/9547958.html [转]虚拟化(三):vsphere套件的安装注意及使用 vsphere套件里面主要的组件有esxi.vcen ...
- 大数据平台搭建 - cdh5.11.1 - oozie安装
一.简介 oozie是hadoop平台开源的工作流调度引擎,用来管理hadoop作业,属于web应用程序,由oozie server 和oozie client构成. oozie server运行与t ...
- java 当前时间月份
public static void main(String[] arg) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd ...
- ios打包时候提示三方文件库错误,整理下解决的思路
这一短时间一直在打包APP上线,今天突然打包的时候碰到的头文件找不到 一开始我以为是路径的问题,检查了targets---Build settings----search Paths----heade ...
- Spring入门(十二):Spring MVC使用讲解
1. Spring MVC介绍 提到MVC,参与过Web应用程序开发的同学都很熟悉,它是展现层(也可以理解成直接展现给用户的那一层)开发的一种架构模式,M全称是Model,指的是数据模型,V全称是Vi ...
- Swoole入门到实战 打造高性能 赛事直播平台(完整版)
Thinkphp+Swoole入门到实战打造高性能赛事直播平台 第1章 课程介绍 欢迎大家来到swoole的课程!本章主要是介绍了swoole的一些特性,以及使用场景,并且分享了swoole在其他公司 ...
- Win10家庭版安装Docker
1.下载Docker Toolbox 下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ 2.安装Docker ...
- 论文阅读 | DeepDrawing: A Deep Learning Approach to Graph Drawing
作者:Yong Wang, Zhihua Jin, Qianwen Wang, Weiwei Cui, Tengfei Ma and Huamin Qu 本文发表于VIS2019, 来自于香港科技大学 ...
- [Optimized Python] 17 - Performance bottle-neck
前言 对于一门编程语言,没接触到“优化”和“库代码”的源码理解程度,不足以谈“掌握”二字. 本篇的学习笔记,同时也意味着自己终于触及到了Python的junior国际水准.(joke) 要学的东西有很 ...
- [Spark] 00 - Install Hadoop & Spark
Hadoop安装 Java环境配置 安装课程:安装配置 配置手册:Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04[依照步骤完成配置] jsk安装使用的链接中第 ...