Search code examples
linuxbashzipunzip

Force directory name from zip


Is there any way to zip a file so that when it is downloaded and unzipped a second time, the directory name is the same?

Desired Outcome:

  • Customer downloads zip file foo.zip and unzips to a directory that is foo.
  • Customer downloads same named zip file a second time and in his/her directory is now foo.zip(1). This time when the file is unzipped it is still foo and NOT foo(1). The user is asked to overwrite existing file.

Solution

  • a way to zip it so that the directory name is forced no matter what the OS and or program is

    No, this is impossible for multiple reasons. If the zip standard had such a policy ...

    • someone could always write a program that ignored the standard and name the extracted files differently.
    • the forced name had to be usable on all operating systems and file systems, otherwise you wouldn't be able to extract the archive on these systems. Name restrictions have to be at least "no names containing <>:"/\|?*" and "no CON, PRN, AUX, NUL, COM1, ..." for Windows, but also ridiculous things like "only 8 characters" for old FAT file systems.