78

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?

Daniel Beck
  • 111,893
danixd
  • 1,524

10 Answers10

133

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
  • 1,626
  • 1
  • 10
  • 6
7

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.

4

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.

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
  • 265
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
  • 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
  • 378
2

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

Daniel Beck
  • 111,893
0

Compress a folder with the name folderName in the current directory(except all hidden files and __MACOSX).

zip -r folderName.zip ./folderName -x "*/.*" -x "__MACOSX"

Compress all files in the current directory (except all hidden files and __MACOSX).

zip -r fileName.zip ./ -x "*/.*" -x "__MACOSX"
BenRoe
  • 111
0

Michiel's answer was almost what I was looking for until I found out that the archive does not include parent folder which is highly necessary for WordPress plugin developers once you are trying to archive a plugin.

If WordPress plugin does not include the container folder, then WordPress is unable to install a plugin.

So I spent quite a bit of time trying to learn Shell commands and testing until I came up with a working solution that would include the container folder inside the newly created archive.

And this is the script you can copy and reuse:

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

Created an in-depth article about this topic on my blog with additional images and notes here.

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
  • 732