zoukankan      html  css  js  c++  java
  • 文件解压压缩

    调用了7z.exe。首先先搜索硬盘内的压缩文件,没有搜索到直接进行下载(有待添加)。其次,进行文件的压缩和解压...部分功能有待完善,代码没有任何技术含量,无非是保持对技术的热爱。

    #include <stdio.h> 
    #include <stdlib.h> 
    #include <windows.h> 
    #include <string.h> 
    #include <time.h> 
    const int LEN = 1024;
    
    void ShowTime();
    void Search();
    void Compress();
    void Decompress();
    void Help();
    
    int main() 
    {	
    	int n = 0;
    	while(n!=5)
    	{
    		ShowTime();
    		printf("               =================================================          \n");
    		printf("               +++++++++++++++++++++++++++++++++++++++++++++++++          \n");
    		printf("               1++++++++++++++++++++Search+++++++++++++++++++++1          \n");
    		printf("               2+++++++++++++++++++Compress++++++++++++++++++++2          \n");
    		printf("               3+++++++++++++++++++Decompress++++++++++++++++++3          \n");
    		printf("               4+++++++++++++++++++++Help++++++++++++++++++++++4          \n");
    		printf("               5+++++++++++++++++++++Exit++++++++++++++++++++++5          \n");
    		printf("               +++++++++++++++++++++++++++++++++++++++++++++++++          \n");
    		printf("               =================================================          \n");
    
    		printf("请选择操作类型:\n");
    		scanf("%d",&n);
    		switch(n)
    		{
    		case 1 : Search();break;
    		case 2 : Compress();break;
    		case 3 : Decompress();break;
    		case 4 : Help();break;
    		case 5 : return 0;break;
    		default : printf("输入错误\n");
    
    		}
    	}
    	return 0; 
    }
    
    void ShowTime()
    {
    	time_t now;
    	now = time(NULL);
    	printf("                         %s", ctime(&now)); 
    	Sleep(1000);
    	//system("cls");
    }
    
    void DirectoryList(LPCSTR Path)
    {
    	WIN32_FIND_DATA FindData;
    	HANDLE hError;
    	int FileCount = 0;
    	char FilePathName[LEN];
    
    	char FullPathName[LEN];
    	strcpy(FilePathName, Path);
    	strcat(FilePathName, "\\*.*");
    	hError = FindFirstFile(FilePathName, &FindData);
    	if (hError == INVALID_HANDLE_VALUE)
    	{
    		printf("搜索失败!");
    		return;
    	}
    	while(::FindNextFile(hError, &FindData))
    	{
    		if (strcmp(FindData.cFileName, ".") == 0 
    			|| strcmp(FindData.cFileName, "..") == 0 )
    		{
    			continue;
    		}
    
    		wsprintf(FullPathName, "%s\\%s", Path,FindData.cFileName);
    		FileCount++;
    		printf("\n%d  %s  ", FileCount, FullPathName);
    
    		if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    		{
    			printf("<Dir>");
    			DirectoryList(FullPathName);
    		}
    	}
    }
    
    void Search()
    {
    	char path[LEN];
    	printf("\nplease input the file Directory\n");
    	scanf("%s",path);
    	DirectoryList(path);
    }
    
    void Compress()
    {
    	char filename[100] = {'\"'};
    	char cmd[300] = "7z.dll a ";
    	//DOS下进入有空格文件夹需要加双引号
    	printf("\nplease input the file name\n");
    	scanf("%s", filename);
    	strcat(cmd, "output ");//生成名为output压缩文件
    	strcat(cmd, filename);//要压缩的文件名
    	system(cmd); 
    	//system("cls"); 
    	//cmd 命令最后是这样的:"C:\Program Files\WinRAR\winrar" a output filename
    	//其中a是程序运行的参数 output是压缩包文件名 filename是输入的文件名
    	//rar命令的语法请参照rar帮助文档
    	printf("压缩完成!!\n");
    	Sleep(2000);
    }
    
    
    void Decompress()
    {
    	char filename[100] = {'\"'};
    	char cmd[300] = "7z.dll e ";
    	printf("\nplease input the file name\n");
    	scanf("%s", filename);
    	strcat(cmd, filename);
    	system(cmd); 
    	printf("解压完成!!\n");
    	Sleep(2000);
    }
    
    void Help()
    {
    	char cmd[300] = {0};
    	strcpy(cmd,"7z.dll -h");
    	system(cmd);
    	Sleep(2000);
    }


  • 相关阅读:
    基于WS流的RTSP监控,H5低延时,Web无插件,手机,微信ONVIF操控摄像头方案
    H5微信视频,直播低延时,IOS限制全屏播放,自动播放问题处理。
    最新IOS,safari11中对webrtc支持,IOS和android视频聊天,web低延时视频教学技术分析
    MySql 用户篇
    Sql Server 数据库帮助类
    [C#基础知识]转载 private、protected、public和internal的区别
    Mysql 插入语句
    .net core identityserver4 学习日志
    mysql 事务模板
    .net core 生成二维码
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835257.html
Copyright © 2011-2022 走看看