Keep original folder creation, modification times

Jul 29, 2009 at 3:54 PM

Is there a way in DotNetZip, which I am using to create and extract a zip file, to retain, for each folder saved/extracted, the original folders' create and modify time?  Files do this now, but not folders.  Folders now get the current date/time.

Coordinator
Jul 29, 2009 at 9:10 PM

Can you show me your code? 

When I zip up a directory, using AddDirectory() it sets the time on the toplevel folder in the archive, to the time on the toplevel folder in the filesystem.  All subfolders get the appropriate time, too. 

What version of the library are you using?

Jul 29, 2009 at 9:28 PM

This is the version I am using, downloaded yesterday.

This is the code:

Using zip As ZipFile = New ZipFile()

                Debug.Print("start zip " & Format(Now, "MMM d, yyyy h:mm:ss tt"))

                zip.AddDirectory("e:\custdrives\jeb\")

                Debug.Print("start zip - saved " & Format(Now, "MMM d, yyyy h:mm:ss tt"))

                zip.EmitTimesInWindowsFormatWhenSaving = True

                zip.Save("e:\MyZipFile.zip")

                Debug.Print("stop zip - saved " & Format(Now, "MMM d, yyyy h:mm:ss tt"))

            End Using

            Using zip As ZipFile = ZipFile.Read("e:\MyZipFile.zip")

                Debug.Print("start zip extract " & Format(Now, "MMM d, yyyy h:mm:ss tt"))

                zip.ExtractAll("e:\windotnetzip\", ExtractExistingFileAction.OverwriteSilently)

                Debug.Print("stop zip extract " & Format(Now, "MMM d, yyyy h:mm:ss tt"))

            End Using

(I tried it without the EmitTimesIn… also, got similar result.  The only thing different I believe is FileCreation date stayed as original without it (EmitTimes…), but became current date/time with it.)

This is what the (original) folders I am zipping up look like (see “Date Modified” column):

This is what they look like after being “ExtractAll”:

 

Thank you for your help.

--Kate Carbery

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Wednesday, July 29, 2009 5:11 PM
To: Kate Carbery
Subject: Re: Keep original folder creation, modification times [DotNetZip:63884]

From: Cheeso

Can you show me your code?

When I zip up a directory, using AddDirectory() it sets the time on the toplevel folder in the archive, to the time on the toplevel folder in the filesystem. All subfolders get the appropriate time, too.

What version of the library are you using?

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Jul 29, 2009 at 10:37 PM

Kate, I can't see any of those pictures on the forums.

I think I know what is happening, though.

When you zip up a directory with AddDirectory(directoryName), all the files in the directory go into the top level directory in the archive.  If the folder that you are zipping up is e:\whatever\jeb, then the folder in the archive is ... nothing.  no folder.

Then, when you extract the zip file via ExtractAll(), you specify a folder to which the zip entries will be extracted. If this is a new folder, as I think it might be in your case, then the folder is created.  If it is created the folder gets the current time as creation time, obviously.  Then the files in the zip are extracted to that folder.

If you have subdirectories in the directory you are zipping up, in other words if you have e:\whatever\jeb\folder1 and e\whatever\jeb\folder2, and you call AddDirectory("e:\whatever\jeb"), the subdirectory entries in the zip archive get the last-mod time equal to the last-mod time of the folder in the filesystem.  Then if you extract with ExtractAll("e:\newFolder") you will see that while e:\newFolder is newly created and has a timestamp of "right now", the subfolders e:\newfolder\folder1 and e:\newfolder\folder2 have last-mod times equal to the times on the original folders in the filesystem.

Does that make sense?

If you want to get a folder in the extract directory that has the same timestamp as the original folder, then you can use the overload of AddDirectory that takes 2 strings.  AddDirectory("e:\whatever\jeb\", "jeb") will put the folder e:\whatever\jeb and its contents into the zip file, under a toplevel directory called "jeb".  The toplevel directory gets the timestamp from e:\whatever\jeb. 

This is a long-winded way of saying you may be able to get what you want by changing one line of code in your app.  Change zip.AddDirectory("e:\custdrives\jeb\") to zip.AddDirectory("e:\custdrives\jeb\", "jeb") .

 

Jul 30, 2009 at 6:45 PM

I understand what you mean about the top-level folder (and too bad about the pictures), but my test included many dozens of subfolders at several levels and all, at every level, get the current date/time when extracted rather than the original.  (Tried your suggestion also, that did not help this.)  Apparently you do not see this behavior on your PC though.

I’ve seen a few other references to this issue on the web, and WinRAR for instance has an explicit switch to achieve original date/times on folders, but I’ve heard from others that when using WinZip sometimes they get original folder dates and sometimes not.  Maybe it is a Zip issue then, but I cannot find any reference to it as such, nor a solution.  Unfortunately I really need an exact copy of the data, including those creation and modification dates.  Thanks for your help.    

--Kate

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Wednesday, July 29, 2009 6:37 PM
To: Kate Carbery
Subject: Re: Keep original folder creation, modification times [DotNetZip:63884]

From: Cheeso

Kate, I can't see any of those pictures on the forums.

I think I know what is happening, though.

When you zip up a directory with AddDirectory(directoryName), all the files in the directory go into the top level directory in the archive. If the folder that you are zipping up is e:\whatever\jeb, then the folder in the archive is ... nothing. no folder.

Then, when you extract the zip file via ExtractAll(), you specify a folder to which the zip entries will be extracted. If this is a new folder, as I think it might be in your case, then the folder is created. If it is created the folder gets the current time as creation time, obviously. Then the files in the zip are extracted to that folder.

If you have subdirectories in the directory you are zipping up, in other words if you have e:\whatever\jeb\folder1 and e\whatever\jeb\folder2, and you call AddDirectory("e:\whatever\jeb"), the subdirectory entries in the zip archive get the last-mod time equal to the last-mod time of the folder in the filesystem. Then if you extract with ExtractAll("e:\newFolder") you will see that while e:\newFolder is newly created and has a timestamp of "right now", the subfolders e:\newfolder\folder1 and e:\newfolder\folder2 have last-mod times equal to the times on the original folders in the filesystem.

Does that make sense?

If you want to get a folder in the extract directory that has the same timestamp as the original folder, then you can use the overload of AddDirectory that takes 2 strings. AddDirectory("e:\whatever\jeb\", "jeb") will put the folder e:\whatever\jeb and its contents into the zip file, under a toplevel directory called "jeb". The toplevel directory gets the timestamp from e:\whatever\jeb.

This is a long-winded way of saying you may be able to get what you want by changing one line of code in your app. Change zip.AddDirectory("e:\custdrives\jeb\") to zip.AddDirectory("e:\custdrives\jeb\", "jeb") .

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Jul 30, 2009 at 7:04 PM

No, not a zip thing.  It's a problem in DotNetZip .  Let me have a look.

Coordinator
Jul 30, 2009 at 7:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jul 30, 2009 at 9:18 PM

Kate, I think I fixed your problem.  can you download v1.8.4.13 and retry?

Aug 3, 2009 at 2:48 PM

Hi sorry for delay, took a long weekend…

I tried v1.8.4.14 today.  Subfolder dates (when zipped up and extracted via DotNetZip) are no longer the current-date, but they don’t quite match the originals either.  From several tests I ran, it appears that if a subfolder has no further subfolders or files, then the modification and creation date do match the original.  If however they have files in them or sub-subfolders with files, then the subfolder gets modification & creation dates from those files (I think), seemingly randomly, like not the most recent or most remote dates.  Seems to happen at any level (I only have about 3 levels in my test data).  I’d be happy to send test data and/or screen shots if it will help.

--Kate

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Thursday, July 30, 2009 5:19 PM
To: Kate Carbery
Subject: Re: Keep original folder creation, modification times [DotNetZip:63884]

From: Cheeso

Kate, I think I fixed your problem. can you download v1.8.4.13 and retry?

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Aug 3, 2009 at 5:58 PM

Hello Kate,

Thanks for getting back to me.  I hope you went somewhere good.

I expanded my test app, and reproduced the behavior you saw.  I think I have a fix for this now (again). 

I've uploaded an updated library to workitem 8264.  Can you check it out? 

 

Aug 3, 2009 at 9:08 PM

Looking very very good!  One test I did (accidentally) was a huge thing with 42,000 folders, nearly 2GB total, and just that one didn’t seem to work, but let me try it again, possibly I messed up.  Other tests looked terrific.  Let you know Tuesday am.

--Kate

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Monday, August 03, 2009 1:59 PM
To: Kate Carbery
Subject: Re: Keep original folder creation, modification times [DotNetZip:63884]

From: Cheeso

Hello Kate,

Thanks for getting back to me. I hope you went somewhere good.

I expanded my test app, and reproduced the behavior you saw. I think I have a fix for this now (again).

I've uploaded an updated library to workitem 8264. Can you check it out?

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Aug 3, 2009 at 9:08 PM

(I meant that big test was 42,000 files, was only 1,300 folders).

--Kate

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Monday, August 03, 2009 1:59 PM
To: Kate Carbery
Subject: Re: Keep original folder creation, modification times [DotNetZip:63884]

From: Cheeso

Hello Kate,

Thanks for getting back to me. I hope you went somewhere good.

I expanded my test app, and reproduced the behavior you saw. I think I have a fix for this now (again).

I've uploaded an updated library to workitem 8264. Can you check it out?

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Aug 4, 2009 at 12:52 PM

Works great, no problems – thank you very much!

--Kate

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Monday, August 03, 2009 1:59 PM
To: Kate Carbery
Subject: Re: Keep original folder creation, modification times [DotNetZip:63884]

From: Cheeso

Hello Kate,

Thanks for getting back to me. I hope you went somewhere good.

I expanded my test app, and reproduced the behavior you saw. I think I have a fix for this now (again).

I've uploaded an updated library to workitem 8264. Can you check it out?

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com