Removing DS_Store files from network shares.

As a mac user, I am quite familiar with the .DS_Store file. This file, hidden on macs and linux because of the '.' at the front of the filename, handles custom finder settings for the folder it's contained in, such as layout, view mode and icons.

On a windows file server or NAS, these files are no longer hidden, and as by default a mac will make these in every network shared folder it you navigate into, they will rapidly start cluttering up your filesystem.

There are two main ways of solving this.

1: Disable .DS_Store on network shares on the mac.

Simply open a Terminal window (/Applications/Utilities/, type the following content and press enter.

defaults write DSDontWriteNetworkStores -bool true

This will prevent your mac making more files, but you need to restart your computer (or relaunch Finder) for this to take effect. Now, let's make a script to remove all the current ones from your server.

2: Periodically remove .DS_Store files from the server.

The script below can either be entered manually into Command Prompt, or saved as a batch file for use later. Simply save it using notepadĀ as a '.bat' file.

Here, D represents the drive letter of my NAS drive. You will probably need to change it to suit your setup.

cd D:\
del /s .DS_Store

If you are running this in a batch file, you may like to add


to the end of the file so that the window stays open for you to see the results. It's probably best to not include this command however if you are running it as a scheduled task as it will cause the command prompt executable to remain open waiting for user input.

Published 2016-09-03