Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, October 7, 2016

Mac zip compress without __MACOSX folder?

Mac zip compress without __MACOSX folder?


When I compress files with the built in zip compressor in Mac OSX, it results in an extra folder titled "__MACOSX" created in the extracted zip.

Can I adjust my settings to keep this folder from being created or do I need to purchase a third party compression tool?

UPDATE: I just found a freeware app for OSX that solves my problem: "YemuZip"

Answer by Ken Thomases for Mac zip compress without __MACOSX folder?


Do you mean the zip command-line tool or the Finder's Compress command?

For zip, you can try the --data-fork option. If that doesn't do it, you might try --no-extra, although that seems to ignore other file metadata that might be valuable, like uid/gid and file times.

For the Finder's Compress command, I don't believe there are any options to control its behavior. It's for the simple case.

The other tool, and maybe the one that the Finder actually uses under the hood, is ditto. With the -c -k options, it creates zip archives. With this tool, you can experiment with --norsrc, --noextattr, --noqtn, --noacl and/or simply leave off the --sequesterRsrc option (which, according to the man page, may be responsible for the __MACOSX subdirectory). Although, perhaps the absence of --sequesterRsrc simply means to use AppleDouble format, which would create ._ files all over the place instead of one __MACOSX directory.

Answer by sinuhepop for Mac zip compress without __MACOSX folder?


When I had this problem I've done it from command line:

zip file.zip uncompressed

Answer by Chris Johnson for Mac zip compress without __MACOSX folder?


Can be fixed after the fact by zip -d filename.zip __MACOSX/\*

Answer by Adil Hussain for Mac zip compress without __MACOSX folder?


This command did it for me:

zip -r Target.zip Source -x "*.DS_Store"  

Target.zip is the zip file to create. Source is the source file/folder to zip up. And the _x parameter specifies the file/folder to not include. If the above doesn't work for whatever reason, try this instead:

zip -r Target.zip Source -x "*.DS_Store" -x "__MACOSX"  

Answer by pompalini for Mac zip compress without __MACOSX folder?


Ok after dwelling on this myself found this solution, from terminal:

zip -r -X Archive.zip *  

Where -X means: Exclude those invisible Mac resource files such as ?_MACOSX? or ?._Filename? and .ds store files

source

Answer by user4669748 for Mac zip compress without __MACOSX folder?


The zip command line utility never creates a __MACOSX directory, so you can just run a command like this:

zip directory.zip -x \*.DS_Store -r directory  

In the output below, a.zip which I created with the zip command line utility does not contain a __MACOSX directory, but a 2.zip which I created from Finder does.

$ touch a  $ xattr -w somekey somevalue a  $ zip a.zip a    adding: a (stored 0%)  $ unzip -l a.zip  Archive:  a.zip    Length     Date   Time    Name   --------    ----   ----    ----          0  01-02-16 20:29   a   --------                   -------          0                   1 file  $ unzip -l a\ 2.zip # I created `a 2.zip` from Finder before this  Archive:  a 2.zip    Length     Date   Time    Name   --------    ----   ----    ----          0  01-02-16 20:29   a          0  01-02-16 20:31   __MACOSX/        149  01-02-16 20:29   __MACOSX/._a   --------                   -------        149                   3 files  

-x .DS_Store does not exclude .DS_Store files inside directories but -x \*.DS_Store does.

The top level file of a zip archive with multiple files should usually be a single directory, because if it is not, some unarchiving utilites (like unzip and 7z, but not Archive Utility, The Unarchiver, unar, or dtrx) do not create a containing directory for the files when the archive is extracted, which often makes the files difficult to find, and if multiple archives like that are extracted at the same time, it can be difficult to tell which files belong to which archive.

Archive Utility only creates a __MACOSX directory when you create an archive where at least one file contains metadata such as extended attributes, file flags, or a resource fork. The __MACOSX directory contains AppleDouble files whose filename starts with ._ that are used to store OS X-specific metadata. The zip command line utility discards metadata such as extended attributes, file flags, and resource forks, which also means that metadata such as tags is lost, and that aliases stop working, because the information in an alias file is stored in a resource fork.

Normally you can just discard the OS X-specific metadata, but to see what metadata files contain, you can use xattr -l. xattr also includes resource forks and file flags, because even though they are not actually stored as extended attributes, they can be accessed through the extended attributes interface. Both Archive Utility and the zip command line utility discard ACLs.

Answer by Alejandro Pablo Tkachuk for Mac zip compress without __MACOSX folder?


You can't.

But what you can do is delete those unwanted folders after zipping. Command line zip takes different arguments where one, the -d, is for deleting contents based on a regex. So you can use it like this:

zip -d filename.zip __MACOSX/\*  

Answer by SabU for Mac zip compress without __MACOSX folder?


The unwanted folders can be also be deleted by the following way:

zip -d filename.zip "__MACOSX*"  

Works best for me

Answer by benedikt for Mac zip compress without __MACOSX folder?


I'm using this Automator Shell Script to fix it after. It's showing up as contextual menu item (right clicking on any file showing up in Finder).

while read -r p; do    zip -d "$p" __MACOSX/\*    zip -d "$p" \*/.DS_Store  done  
  1. Create a new Service with Automator
  2. Select "Files and Folders" in "Finder"
  3. Add a "Shell Script Action"

automator shell script
contextual menu item in Finder

Answer by Dean Payne for Mac zip compress without __MACOSX folder?


Using an Third party app like Blue Harvest can help. It can clean the zip file with a simple right click command.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.