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!
-
You need to be clearer about what you are actually doing, what your code is, and why you are having a problem; as it is your question makes little sense. If you are writing your own zip extractor then you must be reading the zip archive's directory and as part of that you obtain the file/folder names it contains; those names can be modified in any way you choose, e.g. to avoid a name clash, before creating the item on disk containing the unzipped data. If your issue is how to resolve name clashes then it is nothing to do with zip *per se*, so ask specifically about that, showing your code. HTH – CRD Jul 31 '18 at 06:54
-
@CRD I am Using sszipArchive library here is code " [SSZipArchive unzipFileAtPath:zipFilePath toDestination:destinationPath];" first time unzipping working fine but from second i am not getting copy of that file(because of name clash) so, how do i rename the filename while unzipping. – premkolindala Jul 31 '18 at 07:22
1 Answers
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 yourdestinationPath
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

- 52,522
- 5
- 70
- 86
-
I am unable rename the unzipped while moving from temp directory to destination actually i am unable to get the name of file from temporary directorary. – premkolindala Jul 31 '18 at 12:53