c# - Extracted file changes Date modified -


when tried extract file using winrar, retains date modified of file inside .gz. when extracted using code working (i got 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 modified date of extracted file current date date , time extracted it.

how can able retain date modified of file?

example file in .gz dated 8/13/2014 using winrar didn't change when use code changes current date extracted it.

to technically correct not extracting file writing decompressed stream stream file in case. after @ way obvious last write date of file changed.

if want last write time of destination file same compressed filed, can use file.setlastwritetime method (http://msdn.microsoft.com/en-us/library/system.io.file.setlastwritetime(v=vs.110).aspx):

file.setlastwritetimeutc(newfilename, filetodecompress.lastwritetimeutc); 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -