Search code examples
objective-cmacoscocoaunzip

How to unzip the same zip file multiple times?


I am developing a zip extractor app for which if i unzip multiple times the same zip file it should extract like myfile-1, myfile-2, myfile-3 something like this . example : there is sampleproject.zip in my desktop when i unzip it should be like sampleproject, sampleproject-1, sampleproject-2. Any Suggestions. Thanks in Advance!


Solution

  • Based on your comment I suggest you unzip your file to a temporary directory and then move its contents into the actual directory, handling any name clashes as you do that. In outline:

    1. Use URLForDirectory:inDomain:appropriateForURL:create:error: to create a temporary directory suitable to unzip into. You should pass your the URL of your destinationPath for the appropriateForURL: parameter; this should give you a temporary directory on the same volume as destinationPath making placing the unzipped items into the right place moves rather than copies.

    2. Unzip into the temporary directory returned by (1)

    3. Now use NSFileManager calls to traverse the temporary directory moving each item found to destinationPath, renaming as needed to avoid name clashes.
    4. Remove the temporary directory.

    If you have problems implementing this algorithm ask a new question, show your code, explain your problem, and include a link back to this question so the thread can be followed. Someone will then undoubtedly help you with the next step.

    HTH