2013-04-15 94 views
5

SevenZipsharpを使用してボリューム内のファイルを圧縮したいとします。たとえば、100 MBのファイルをそれぞれ10 MBの10個のファイルに圧縮する場合などです。私たちは、7zip.exe -volumeパラメータそう...例えばSevenZipSharpをマルチボリュームで圧縮するには?

、私は7zipをを使用して、マルチボリュームに圧縮したときに、私はこれらのファイルの構造を得るを使用して同じ操作を行うことができます。

File.7z.001 
File.7z.002 
File.7z.003 
etc... 

ファイルがindependientではありません、同じサイズの7zipファイルの量ではありません、私は最初のファイル "File.7z.001"を必要とするコンテンツ全体を抽出することを意味します。

私は同じにしたいSevenZipSharpを使用しているもの(可能な場合)。

I(答えはC#コードである場合は関係なく)vb.netでこのスニペットを作った、私はマルチボリュームのオプションを実装する必要があり、私は助けを必要とする:

Imports SevenZip 

    Dim dll As String = "7z.dll" 

    Private Function SevenZipSharp_Compress(ByVal Input_DirOrFile As String, _ 
             Optional ByVal OutputFileName As String = Nothing, _ 
             Optional ByVal Format As OutArchiveFormat = OutArchiveFormat.SevenZip, _ 
             Optional ByVal CompressionMode As CompressionMode = CompressionMode.Create, _ 
             Optional ByVal CompressionMethod As CompressionMethod = CompressionMethod.Lzma, _ 
             Optional ByVal CompressionLevel As CompressionLevel = CompressionLevel.Normal, _ 
             Optional ByVal Password As String = Nothing) As Boolean 
     Try 
      ' Set library path 
      SevenZipExtractor.SetLibraryPath(dll) 


     ' Create compressor and specify the file or folder to compress 
     Dim Compressor As SevenZipCompressor = New SevenZipCompressor() 

     ' Set compression parameters 
     Compressor.CompressionLevel = CompressionLevel ' Archiving compression level. 
     Compressor.CompressionMethod = CompressionMethod ' Append files to compressed file or overwrite the compressed file. 
     Compressor.ArchiveFormat = Format ' Compression file format 
     Compressor.CompressionMode = CompressionMode ' Compression mode 
     Compressor.DirectoryStructure = True ' Preserve the directory structure. 
     Compressor.IncludeEmptyDirectories = True ' Include empty directories to archives. 
     Compressor.ScanOnlyWritable = False ' Compress files only open for writing. 
     Compressor.EncryptHeaders = False ' Encrypt 7-Zip archive headers 
     Compressor.TempFolderPath = System.IO.Path.GetTempPath() ' Temporary folder path 
     Compressor.FastCompression = False ' Compress as fast as possible, without calling events. 
     Compressor.PreserveDirectoryRoot = True ' Preserve the directory root for CompressDirectory. 
     Compressor.ZipEncryptionMethod = ZipEncryptionMethod.ZipCrypto ' Encryption method for zip archives. 
     Compressor.DefaultItemName = "File.7z" ' Item name used when an item to be compressed has no name, for example, when you compress a MemoryStream instance 

     ' Get File extension 
     Dim CompressedFileExtension As String = Nothing 
     Select Case Compressor.ArchiveFormat 
      Case OutArchiveFormat.SevenZip : CompressedFileExtension = ".7z" 
      Case OutArchiveFormat.BZip2 : CompressedFileExtension = ".bz" 
      Case OutArchiveFormat.GZip : CompressedFileExtension = ".gzip" 
      Case OutArchiveFormat.Tar : CompressedFileExtension = ".tar" 
      Case OutArchiveFormat.XZ : CompressedFileExtension = ".xz" 
      Case OutArchiveFormat.Zip : CompressedFileExtension = ".zip" 
     End Select 

     ' Add Progress Handler 
     'AddHandler Compressor.Compressing, AddressOf SevenZipSharp_Compress_Progress 

     ' Removes the end slash ("\") if given for a directory 
     If Input_DirOrFile.EndsWith("\") Then Input_DirOrFile = Input_DirOrFile.Substring(0, Input_DirOrFile.Length - 1) 

     ' Generate the OutputFileName if any is given. 
     If OutputFileName Is Nothing Then _ 
      OutputFileName = (My.Computer.FileSystem.GetFileInfo(Input_DirOrFile).DirectoryName & "\" & (Input_DirOrFile.Split("\").Last) & CompressedFileExtension).Replace("\\", "\") 

     ' Check if given argument is Dir or File ...then start the compression 
     If IO.Directory.Exists(Input_DirOrFile) Then ' Is a Dir 
      If Not Password Is Nothing Then 
       Compressor.CompressDirectory(Input_DirOrFile, OutputFileName, True, Password) 
      Else 
       Compressor.CompressDirectory(Input_DirOrFile, OutputFileName, True) 
      End If 
     ElseIf IO.File.Exists(Input_DirOrFile) Then ' Is a File 
      If Not Password Is Nothing Then 
       Compressor.CompressFilesEncrypted(OutputFileName, Password, Input_DirOrFile) 
      Else 
       Compressor.CompressFiles(OutputFileName, Input_DirOrFile) 
      End If 
     End If 

    Catch ex As Exception 
     'Return False ' File not compressed 
     Throw New Exception(ex.Message) 
    End Try 

    Return True ' File compressed 


    End Function 

使い方スニペットの:あなたCompressorオブジェクト上

SevenZipSharp_Compress("C:\File or folder", _ 
          "Optional: Output dir", _ 
          OutArchiveFormat.SevenZip, _ 
          CompressionMode.Create, _ 
          CompressionMethod.Lzma, _ 
          CompressionLevel.Ultra, _ 
          "Optional: Password") 

答えて

11

、バイト単位で出力ファイル(単数または複数)の所望のサイズにVolumeSizeを設定します。以下のサンプルコードを使用して、ソースディレクトリに約72MBのmp3ファイルが入っていると、コンプレッサーはzipped.7z.001、zipped.7z.002などの8つの出力ファイルを作成しました。

現在のソースを見るSevenZipExtractorクラスの場合、OutArchiveFormat.SevenZipArchiveFormatとして使用している場合にのみ、マルチボリューム圧縮が利用可能です。私は** VolumeSize **プロパティが前に尋ねるが、いくつかの奇妙な理由で多分理由は、あなたが言ったことを、7zipをフォーマットに対してのみavaliableであるということである、働いていない使用してきました

string dll = @"C:\Users\WarrenG\Desktop\7z.dll"; 
string source = @"C:\Users\WarrenG\Desktop\source"; 
string output = @"C:\Users\WarrenG\Desktop\output\zipped.7z"; 

SevenZipExtractor.SetLibraryPath(dll); 
SevenZipCompressor compressor = new SevenZipCompressor(); 
compressor.ArchiveFormat = OutArchiveFormat.SevenZip; 
compressor.CompressionMode = CompressionMode.Create; 
compressor.TempFolderPath = System.IO.Path.GetTempPath(); 
compressor.VolumeSize = 10000000; // output file size in bytes 
compressor.CompressDirectory(source, output); 
+0

は、少なくとも今7zipをで動作しますフォーマット、よろしく! – ElektroStudios

関連する問題