问题
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!
回答1:
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:
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 theappropriateForURL:
parameter; this should give you a temporary directory on the same volume asdestinationPath
making placing the unzipped items into the right place moves rather than copies.Unzip into the temporary directory returned by (1)
- Now use
NSFileManager
calls to traverse the temporary directory moving each item found todestinationPath
, renaming as needed to avoid name clashes. - 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
来源:https://stackoverflow.com/questions/51592777/how-to-unzip-the-same-zip-file-multiple-times