• 大小: 2.37MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-03-19
  • 语言: C#
  • 标签: c#  7z  

资源简介

SevenZipSharp和7z.dll 进行开发,对文件压缩,效率非常可观。

资源截图

代码片段和文件信息

using SevenZip;
using System;
using System.IO;

namespace Win7z
{
    /// 
    /// 7z压缩
    /// 

    public class R7z
    {
        public R7z()
        {
            var path = Path.Combine(System.AppDomain.CurrentDomain.baseDirectory “7z\\7z.dll“);
            SevenZipbase.SetLibraryPath(path);
        }
        /// 
        /// 压缩文件
        /// 

        /// target.7z
        /// xxx.txtxxx.txt
        /// 
        public bool CompressFiles(string targetName params string[] files)
        {
            try
            {
                var tmp = new SevenZipCompressor();
                tmp.ScanOnlyWritable = true;
                tmp.CompressFiles(targetName files);
                return true;
            }
            catch (Exception)
            { }
            return false;
        }
        /// 
        /// 加密压缩文件
        /// 

        /// target.7z
        /// xxx.txtxxx.txt
        /// 
        public bool CompressFilesEncrypted(string targetName string password params string[] files)
        {
            try
            {
                var tmp = new SevenZipCompressor();
                tmp.ScanOnlyWritable = true;
                tmp.CompressFilesEncrypted(targetName password files);
                return true;
            }
            catch (Exception)
            { }
            return false;
        }
        /// 
        /// 解压文件
        /// 

        /// 压缩的文件
        /// 解压的目标地址下
        /// 解密密码
        /// 
        public bool Decompression(string CompressFile string targetAddress string password = ““)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(password))
                {
                    using (var tmp = new SevenZipExtractor(CompressFile))
                    {
                        for (int i = 0; i < tmp.ArchiveFileData.Count; i++)
                        {
                            tmp.ExtractFiles(targetAddress tmp.ArchiveFileData[i].Index);
                        }
                    }
                }
                else
                {
                    using (var tmp = new SevenZipExtractor(CompressFile password))
                    {
                        for (int i = 0; i < tmp.ArchiveFileData.Count; i++)
                        {
                            tmp.ExtractFiles(targetAddress tmp.ArchiveFileData[i].Index);
                        }
                    }
                }
            }
            catch (Exception)
            { }
            return false;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     44544  2019-09-17 13:33  Win7z\.vs\Win7z\v15\.suo

     文件          0  2019-09-17 11:10  Win7z\.vs\Win7z\v15\Server\sqlite3\db.lock

     文件     454656  2019-09-17 13:25  Win7z\.vs\Win7z\v15\Server\sqlite3\storage.ide

     文件      32768  2019-09-17 11:10  Win7z\.vs\Win7z\v15\Server\sqlite3\storage.ide-shm

     文件    4124152  2019-09-17 13:32  Win7z\.vs\Win7z\v15\Server\sqlite3\storage.ide-wal

     文件       9465  2018-11-03 01:27  Win7z\packages\SevenZipSharp.0.64\.signature.p7s

     文件     151040  2011-07-06 20:47  Win7z\packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll

     文件      90399  2019-09-17 11:20  Win7z\packages\SevenZipSharp.0.64\SevenZipSharp.0.64.nupkg

     文件    1129472  2019-09-17 11:26  Win7z\Win7z\7z\7z.dll

     文件    1484800  2019-09-17 11:26  Win7z\Win7z\7z\7z64.dll

     文件     224768  2019-09-17 11:26  Win7z\Win7z\7z\7za.dll

     文件       3059  2019-09-17 13:32  Win7z\Win7z\7z.cs

     文件        187  2019-09-17 11:10  Win7z\Win7z\App.config

     文件    1129472  2019-09-17 11:26  Win7z\Win7z\bin\Debug\7z\7z.dll

     文件    1484800  2019-09-17 11:26  Win7z\Win7z\bin\Debug\7z\7z64.dll

     文件     224768  2019-09-17 11:26  Win7z\Win7z\bin\Debug\7z\7za.dll

     文件     151040  2011-07-06 20:47  Win7z\Win7z\bin\Debug\SevenZipSharp.dll

     文件       6144  2019-09-17 13:31  Win7z\Win7z\bin\Debug\Win7z.exe

     文件        187  2019-09-17 11:10  Win7z\Win7z\bin\Debug\Win7z.exe.config

     文件      19968  2019-09-17 13:31  Win7z\Win7z\bin\Debug\Win7z.pdb

     文件       6934  2019-09-17 13:13  Win7z\Win7z\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2019-09-17 11:10  Win7z\Win7z\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-09-17 11:10  Win7z\Win7z\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-09-17 11:10  Win7z\Win7z\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件          0  2019-09-17 13:31  Win7z\Win7z\obj\Debug\Win7z.csproj.CopyComplete

     文件         42  2019-09-17 13:13  Win7z\Win7z\obj\Debug\Win7z.csproj.CoreCompileInputs.cache

     文件        675  2019-09-17 11:31  Win7z\Win7z\obj\Debug\Win7z.csproj.FileListAbsolute.txt

     文件      32799  2019-09-17 11:28  Win7z\Win7z\obj\Debug\Win7z.csprojAssemblyReference.cache

     文件       6144  2019-09-17 13:31  Win7z\Win7z\obj\Debug\Win7z.exe

     文件      19968  2019-09-17 13:31  Win7z\Win7z\obj\Debug\Win7z.pdb

............此处省略26个文件信息

评论

共有 条评论