none
Zipfile.createfromdirectory lock problem RRS feed

  • Question

  • I use zipfile.createfromdirectory to zip directories.

    When a file in this directory is locked, the zipping breaks with an error that a file is locked.

    How can I avoid this?

    Monday, February 25, 2013 10:32 AM

Answers

  • Can you skip the locked file or does need to be in archive?

    If you can not skip it then you need to somehow get it unlocked so it can be added to archive. If you can skip it then you might need to create ZipArchive class instance and enumerate files in folder and add those that you can to the archive for example with CreateEntryFromFile extension method. That's how I have done it, but someone more familiar with these classes might know better approach.

    Monday, February 25, 2013 12:00 PM

All replies

  • Can you skip the locked file or does need to be in archive?

    If you can not skip it then you need to somehow get it unlocked so it can be added to archive. If you can skip it then you might need to create ZipArchive class instance and enumerate files in folder and add those that you can to the archive for example with CreateEntryFromFile extension method. That's how I have done it, but someone more familiar with these classes might know better approach.

    Monday, February 25, 2013 12:00 PM
  • Hi Sunt,

    I have temporary marked the reply as answer. If it doesn't work on your side, please feel free to unmark it and follow up this thread.

    Thank you.


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 28, 2013 2:10 PM
    Moderator
  • 5:16 PM 10/26/2013 An Update:-- the issue will occurs if the any file in the directory is locked to write. when right click and zip the file using windows inbuilt zip utility it just zips it correctly. i feel this is a bug in the ZipFile.CreateFromDirectory.

    SOLUTION:--
    6:00 PM 10/26/2013 --UPDATE :--  copy of the folder to another location, the run the ZipFile.CreateFromDirectory command on the copied folder then delete the copied folder.

    Please help log a enhancement request :)

    • Proposed as answer by DD1610 Monday, October 28, 2013 11:29 PM
    • Edited by DD1610 Saturday, November 9, 2013 3:50 AM
    Saturday, October 26, 2013 7:16 AM