I'm executing a zip command from within my app using NSTask. It's passed as arguments some paths which point to the files/folders to be zipped.
The problem is that without the -j option, the final zip ends up with absurd filepaths inside the zip, (like "/private/var/folders/A5/A5CusLQaEo4mop-reb-SYE+++TI/-Tmp-/9101A216-5A6A-4CD6-A477-E4B86E007476-51228-00014BCB9514323F/myfile.rtf"). However, if I add the -j option, then I constantly run into name collisions if any file anywhere deep inside a nested folder has
I've tried setting the path before executing the NSTask:
[[NSFileManager defaultManager] changeCurrentDirectoryPath:path];
In the hope that the documentation for zip was telling the truth:
By default, zip will store the full path (relative to the current directory)
But this did not work as expected. Adjusting settings of -j and -p and -r simply produces the above mentioned problems in different combinations.
QUESTION:
How can I take a set of directories like
- /some/long/path/sub1/file1.txt
- /some/long/path/sub2/file1.txt
and zip them into a zip whose contents are
- /sub1/file1.txt
- /sub2/file1.txt
Thanks for any advice on the subtleties of zip.
-----EDIT
One other thing I forgot to add is that the original directory being passed is "path", so the desired outcome is also to my mind the expected outcome.