I have a file in a current directory, which name is firstName
. I want to create an archive with this file (name of file have to stay). The archive name have to be an archiveName
. But when I use my code I get an archive with the rigth name but the name of file in it was changed. How can I fix it?
public static void Compress(string firstName, string secondName)
{
FileInfo fileToCompress = new FileInfo(firstName);
using (FileStream originalFileStream = fileToCompress.OpenRead())
{
if ((File.GetAttributes(fileToCompress.FullName) &
FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz")
{
using (FileStream compressedFileStream = File.Create(secondName))
{
using (GZipStream compressionStream = new GZipStream(compressedFileStream,
CompressionMode.Compress))
{
originalFileStream.CopyTo(compressionStream);
}
}
FileInfo info = new FileInfo(secondName);
Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
fileToCompress.Name, fileToCompress.Length.ToString(), info.Length.ToString());
}
}
}