When I tried to extract the file using winrar, it will save the date changed for the file inside .gz. But when I extracted it using code that works (I got from other blogs):
public static void Decompress(FileInfo fileToDecompress)
{
using (FileStream originalFileStream = fileToDecompress.OpenRead())
{
string currentFileName = fileToDecompress.FullName;
string date = fileToDecompress.LastWriteTimeUtc.ToString();
MessageBox.Show(date);
string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);
using (FileStream decompressedFileStream = File.Create(newFileName))
{
using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
{
decompressionStream.CopyTo(decompressedFileStream);
Console.WriteLine("Decompressed: {0}", fileToDecompress.Name);
}
}
}
}
It changes the changed date of the extracted file to the current date, which is the date and time that I extracted.
How to save file modification date?
For example, the file in .gz is dated 8/13/2014, using winrar, which it did not change, but when I use my code, it changes to the current date that I extracted.
source
share