SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Modified time of files gets changed while un-zipping :(

Last post 11-02-2007 12:41 AM by jspraul. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 10-27-2007 9:54 AM

    Modified time of files gets changed while un-zipping :(

    Greetings,

    We are unzipping the files which are originally zipped through windows xp zipping utility. While unziping the file through code, the modified time of the files in that zip archive gets changed when extracted. We want to retain it to original in un-zipping. Please help. We are using following code snippet for unzipping.

    =========================================================

     

    public static string unzipThroughCSharp(string filename, string targetdir, bool overwrite, string password)
            {
                try
                {
                    ICSharpCode.SharpZipLib.Zip.ZipInputStream inputStrm = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(filename));
                    inputStrm.Password = password;

                    ICSharpCode.SharpZipLib.Zip.ZipEntry nextEntry = inputStrm.GetNextEntry();

                    while (nextEntry != null)
                    {
                        if (nextEntry.Name.LastIndexOf("/") != nextEntry.Name.Length - 1)
                        {
                            if (nextEntry.Name.IndexOf("/") > 0)
                            {
                                if (!(Directory.Exists(targetdir + @"\" + nextEntry.Name.Replace("/", @"\").Substring(0, nextEntry.Name.Replace("/", @"\").LastIndexOf(@"\")))))
                                {
                                    Directory.CreateDirectory(targetdir + @"\" + nextEntry.Name.Replace("/", @"\").Substring(0, nextEntry.Name.Replace("/", @"\").LastIndexOf(@"\")));

                                }

                            }
                            FileStream tmpStrm;
                            byte[ tmpBuffer = new byte[2049];

     

                            int tmpLength = -1;

                            if (overwrite == true)
                            {
                                tmpStrm = new FileStream(Path.Combine(targetdir, nextEntry.Name), FileMode.Create);
                            }
                            else
                            {
                                tmpStrm = new FileStream(Path.Combine(targetdir, nextEntry.Name), FileMode.CreateNew);
                            }
                            while (true)
                            {
                                tmpLength = inputStrm.Read(tmpBuffer, 0, tmpBuffer.Length);
                                if (tmpLength > 0)
                                { tmpStrm.Write(tmpBuffer, 0, tmpLength); }
                                else
                                { break; }

                            }
                            tmpStrm.Flush();
                            tmpStrm.Close();

                            nextEntry = inputStrm.GetNextEntry();


                        }

                        else
                        {
                            Directory.CreateDirectory(targetdir + @"\" + nextEntry.Name.Replace("/", @"\"));
                            nextEntry = inputStrm.GetNextEntry();
                        }
                    }
                    return "OK";
                }
                catch (Exception ex)
                {
                   
                    return ex.Message;
                    throw ex;
                }

                }

     

     

  • 11-02-2007 12:41 AM In reply to

    Re: Modified time of files gets changed while un-zipping :(

    If you switch to using FastZip, you can use the RestoreDateTimeOnExtract property. Otherwise, set the Date/Time stamp yourself after tmpStrm.Close();

    Something like:

    File.SetLastWriteTime( Path.Combine(targetdir, nextEntry.Name), nextEntry.DateTime);

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.