Compressing folders on a mac, without the .DS_Store

66

37

Is there anyway to get rid of the .DS_Store when compressing a folder on a mac?

I work on a mac and send work to clients in zip format, but always get questioned on the .DS_Store folder inside them. It seems to be unavoidable unless I open the folder on Windows then delete the .DS_Store and compress it there. It is quite a big hassle.

Are there any easy work arounds?

danixd

Posted 2010-10-12T09:03:48.547

Reputation: 1 264

Answers

111

If you do not mind jumping down in to terminal, then this is pretty darn easy. If you are in /Users/username, which is your $HOME directory and there is a subdirectory named foo that you want to zip but ignore all .DS_Store files, then do the following:

zip -r foo.zip foo -x "*.DS_Store"

To interpret this, we are running the zip executable with the following parameters/arguments:

  • -r for recursively including all directories underneath the targets we want to zip.
  • foo.zip is the name of the zip archive we are creating
  • foo is the target directory we want to zip up
  • -x "*.DS_Store" excludes all files whose path ends in the string ".DS_Store"

No goofy third party applications needed nor do you need to trash your .DS_Store files at all - just rely on all of the unix tool goodness built right in to OSX / Darwin.

whaley

Posted 2010-10-12T09:03:48.547

Reputation: 1 376

1This is perfect thanks. Out of interest, how would I exclude multi path endings? Something like zip -r foo.zip foo -x "*.DS_Store, *.svn" ? – danixd – 2010-10-12T14:10:19.960

5Use the -x argument twice: zip -r foo.zip foo -x *.DS_Store -x *.svn* – whaley – 2010-10-12T14:50:40.187

How do you exclude the Icon-files OSX creates for custom folder icons? They have a newline or something like that at the end of the filename. – Daniel Beck – 2010-10-12T17:42:38.140

I have no clue what those filenames look like so I can't give any real guidance here. – whaley – 2010-10-12T18:36:53.087

ls says Icon?, but I think it's ASCII 0x0A at the end. If you have an OS X system, copy & paste an icon from one file info dialog to another (select the icon on the top left and Cmd-C, then on a folder info dialog the same with Cmd-V). Then the file is created within the folder. – Daniel Beck – 2010-10-13T10:54:54.787

As long as this file is not excluded, your solution might be "purer" than the others using third-party utilities etc., but inferior. And I also would like be able to trash one-trick ponies like CleanArchiver. This is why I ask. – Daniel Beck – 2010-10-13T10:56:21.727

1@Daniel Beck - so keep using CleanArchiver and don't hijack the comment section of someone else's question and accepted answer to the call the solution inferior when it obviously works for the original poster? The answer to your question, amazingly enough, is -x 'Icon?'. The "?" character in a file globbing pattern means "match a single wildcard character", so it will match irrespective of what the "?" really is. You can exclude ad-hoc files of any kind by just appending more -x arguments. zip is very flexible. What do you suppose these third party utils really use behind the scenes? – whaley – 2010-10-13T13:23:44.697

I am sure other tools use zip or something comparable internally, which is why I asked in the first place -- the OP already has made up his mind; I merely wanted to provide additional information for others. Since it's very closely related to the question and your answer, my comments belong here. Thanks for the hint with ?; will have to figure out how to unexclude Icons, but it's a start.

– Daniel Beck – 2010-10-13T13:56:42.477

5

You can create an automator application that accepts a folder as input and produces a zip file of the folder contents without any cruft.

Store this application in /Users/you/Applications and then drag it into your finder toolbar. Then you can drag folders onto the app from any finder window.

Create an automator application

Add 'get selected finder items' step. And also add a 'run shell script' step with the 'Pass input' option set to 'as arguments'.

Add workflow steps

The script:

name=("$@")
cd "$name"
zipFileName=`basename "$name"`
zip "${zipFileName}.zip" -r ./* \
    -x */.DS_Store \
    -x */.git \
    -x */.svn \
    -x */.idea \
    -X */__MACOSX
mv "${zipFileName}.zip" ../

Accepts a folder as input and produces a zipfile with the name of the folder.

Michiel Roos

Posted 2010-10-12T09:03:48.547

Reputation: 186

Its great! How can I modify it that i can drag multiple files, output name should be containing dirname; – unbreak – 2018-09-05T10:03:13.023

2@unbreak I don't know. I no longer own a mac ;-) – Michiel Roos – 2018-09-12T11:03:45.173

3

If you've already created the zip archive (or want a simple way of removing .DS_Store post zip creation), this will remove all .DS_Store files at any path in the zip archive:

zip -d archive.zip "*/*.DS_Store"

whaley's answer is still definitely the best, because it can be aliased and forgotten about. In my case, I created the zip from the Archive Utility, then realized I should delete these.

James Taylor

Posted 2010-10-12T09:03:48.547

Reputation: 401

3

I don't think there's a way to do it by default, but there's two ways I can think of to achieve what you want.

First off, I found a free app called FolderWasher. Drop the folder on the app and it'll remove the .DS_Store files and zip it for you.

Alternatively (and potentially better than 3rd party software) you can use Automator to clean the archive after creation. There is actually already an action created for this. That's only one extra step, and you can drag the action to Finder so it's easy to find.

Delameko

Posted 2010-10-12T09:03:48.547

Reputation: 267

2

If you run this in Terminal this stops them auto generated when you create folders, you can turn it back on if you choose.

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

You can then use @Penang example (above) to verify if the files don't get created anymore. I had to upload a zip file and every folder had that file in it and this helped me.

Evan

Posted 2010-10-12T09:03:48.547

Reputation: 121

2

Open Terminal (/Applications/Utilies/Terminal.app) and run the following command to show hidden files:

defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder

To hide the hidden files simply run:

defaults write com.apple.finder AppleShowAllFiles FALSE && killall Finder

You can delete .DS_Store files just like any other files without causing any harm to your directory. As stated on wikipedia, "DS_Store (Desktop Services Store) is a hidden file created by Apple Inc.'s Mac OS X operating system to store custom attributes of a folder such as the position of icons or the choice of a background image."

Penang

Posted 2010-10-12T09:03:48.547

Reputation: 378

2

Use CleanArchiver to create those archives. This way you don't need to trash your folder preferences.

Daniel Beck

Posted 2010-10-12T09:03:48.547

Reputation: 98 421

0

There is an explanation of what they are, and how to delete them on the adobe help site of all places.

They are a hidden file used to store the configuration of a folder (like icon position, color, folder background and scroll position. Unfortunately there seems to be no way to stop them being created permanently, although apple do admit that they can cause problems for some users.

Trezoid

Posted 2010-10-12T09:03:48.547

Reputation: 732