I’ve written a simple batch file to remove those hidden files that Mac OSX leaves all over shared drives to annoy us Windows users.
del /s /a:h ._* :: http://en.wikipedia.org/wiki/Resource_fork del /s /a:h .DS_Store :: http://en.wikipedia.org/wiki/.DS_Store del /s /a:h .Trashes :: http://en.wikipedia.org/wiki/Recycle_bin_(computing) @pause
How to use
Copy the code into a text file, rename it cleanOSX.bat and run it from the root of the drive you wish to clean. The script will look through all subfolders, deleting any hidden file or folder with a name that begins with ._, or that matches .DS_Store or .Trashes. Depending on the number of these files on your drive, the process of deleting them could take some time.
Where do these files come from?
The resource fork
The resource fork is a construct of the Mac OS operating system used to store structured data in a file, alongside unstructured data stored within the data fork. A resource fork stores information in a specific form, such as icons, the shapes of windows, definitions of menus and their contents, and application code (machine code). For example, a word processing file might store its text in the data fork, while storing any embedded images in the same file’s resource fork. The resource fork is used mostly by executables, but every file is able to have a resource fork.
…
Currently, Mac OS X does support resource forks on Windows SMB shares by creating a hidden file in the same directory with the data fork file, with the characters “._” at the beginning of the file name. However, this may be annoying for some users, especially because some Windows power users always keep hidden files visible. Besides, Windows does not treat those files correctly as the file itself is moved or removed.
The Desktop Services Store
.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.
The Trash folder
Under Mac OS X, when a file is deleted in Finder, it is moved to a .Trashes folder, and when viewing the device’s available space the space occupied by the deleted files is shown as occupied.
hi! i couldnt find a way to run the file, not even as logged as root.
do you have any ideas how can i run the file? thx
Dear Ja
you said logged in as root but this is a dos batch file and the term root etc is a unix/OSX term
so you need to do this in windows
programs run cmd
then log onto the drive letter appropriately and cd
then run the batch file you created or run the commands separately and manually
This really saved me heaps of tedious time wastage.. Thank you so much for this..
btw, i hope you don’t mind me sharing it on my site (http://www.sur3wyn.com/2011/04/how-to-delete-all-hidden-files-on-mac.html) 🙂
thank’s, great script !! simple, no installation, no spyware 😉
Great little scriptlet! Just saved me from having to cough up a script of my own to clean up our shared drive that is used by 5% macs, 95% PCs. Now to figure out how to turn that ._stuff ._off!
Thanks for helping me clean up all the OSX droppings that were littering my drive!
great script. thank you!
It doesn’t erase the hidden folders.
You also got some of the code wrong. DEL command can’t erase folders, so this doesn’t work: “del /s /a:h .Trashes”. .Trashes is a folder.
Here’s an updated script that will work in all situations, regardless of whether your mac litter is hidden or not. It also doesn’t bug you for confirmation. Hope it helps:
del /s /a:h /a:a /q ._*
del /s /a:h /a:a /q .DS_Store
rmdir /s /q .Trashes
rmdir /s /q .Spotlight-V100
rmdir /s /q .fseventsd
del /s /a:h /a:a /q autorun.inf
del /s /a:h /a:a /q icon.ico
@pause
Thank you ardamis and bobwilson.
Worked a treat.
I flick between both mac and win and the junk, especially trashes, clogs my memory stick.
err am I right in assuming that win does not use ._ for *anything* ?
I know it is safe on my memory stick but are there any w7 (or w8) things that use/need ._ ?
Thanks! This was a huge time saver!
thankyou so much!! it is a huge time saver!
You have no idea how this helped me… Thanks man
the best solution is to format your external drive in exFat. Solves the issue. And that’s from apple care.
I’m trying the del /s /a:h /a:a /q .DS_Store in the top level of the directory I am trying to clean and it’s telling me it “Could not find …”. I have tried running the command prompt as admin and it still doesn’t work. Any ideas?
Hi, thanks for the very very helpful hint !!!
Trying to use it to get rid of some files….
Any idea why:
if exist “%letter%:\*.*” del /s /a:h /a:a /q %letter%:\*.eit
is correct deleting all *.eit files
but:
if exist “%letter%:\*.*” del /s /a:h /a:a /q %letter%:\*.ts.cuts
doesn’t work ??
Thank you for help 🙂
Thanks much for the very helpful script.
Regarding Bob Wilson’s comment, I’m not sure why he thought the script as posted doesn’t work on hidden files or folders or needs to use RMDIR – the DEL command certainly does delete folders, and the /a:h makes sure hidden files/folders are being selected for deletion. Works just fine for me.
However the original script erred in supplying the /s switch when deleting the .Trashes folder, as this recyclebin is only ever at the top level, hence no recursion should be used while deleting it.
The amended suggestion by Bob Wilson to also remove the .Spotlight-V100 and ,fseventsd folders is useful though, but that he also chooses to remove standard Windows portable media files autorun.info and icon.ico is not appropriate in this context, that’s just a personal preference if he doesn’t like having those.