0

I've a problematic situation where I should compress an file and so rename it to what the user choose + ".zip"/".rar"/".tar.gz"/".tar".

About compress itself is everything Ok, but when I try to rename the file with something like File.Move() or FileInfo.Move() , the name of the compressed file also changes, just like the file extension. Example:

string pathFile = "C:\\Users\\Admin\\Desktop\\myFile.exe";
string finalPath = "C:\\Users\\Admin\\Desktop\\userFile.zip";
string compressedPath = "C:\\Users\\Admin\\Desktop\\myFile.exe.zip";

...

File.Move(compressedPath, finalPath);

The problem here is who userFile.zip , when decompressed, generates a userFile file, without extension. Previously I read that compressed files by GZIP don't have information bisides the byte[] array who was written, and this is the possible cause.

But I want to know if someone knows a way to rename GZIP files or another way to compress files and rename with .NET framework.

Thank you.

1 Answers1

0

https://msdn.microsoft.com/en-us/library/ms404280(v=vs.110).aspx

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}
Mikes3ds
  • 592
  • 5
  • 12