How to compress files into multiple files with specific sizes?

Asked

Viewed 147 times

0

I have several files in one folder, these files are already . zip files, . 7zip, . rar...

To facilitate the work of handling these files, I wanted to divide them into smaller files using c#.

Is there any way to split these files into smaller files without needing to unzip them with some function or package?

1 answer

1


Using the Ionic.Zip library you can do this. But you will create new compact files containing your compressed files.

public static void ComprimirEmPartes(string diretorio, string arquivoSaida)
{
    using (var zip = new ZipFile())
    {
        //Serão compactados novamente todos os arquivos dessa pasta
        zip.AddDirectory(diretorio);

        //Serão gerados arquivos com no máximo 5MB
        zip.MaxOutputSegmentSize = 5 * 1024 * 1024; // 5MB
        zip.Save(arquivoSaida);

        //TO DO: Aqui você poderia ir apagando os arquivos já processados.
    }
}

public static void ExtrairTudo(string arquivoZip, string diretorioSaida)
{
    using (var z = ZipFile.Read(arquivoZip))
    {
        z.ExtractAll(diretorioSaida);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.