I extracted a .zip file compressed on a Mac and discovered that the compression included all the .DS_STORE meta-directory files (I think used to speed up spotlight search, but besides the point?).

Is there a one-liner I can execute from a Windows PowerShell or simple python script to clean up this folder by recursively deleting these files?

I get the error: FIND: Parameter format not correct when using:

find . -name '*.DS_Store' -type f -delete
  • The easiest way would be just to search for the files in Windows Explorer (ctrl-f), highlight them, and then delete them. – dangph Mar 30 '15 at 7:45

In PowerShell do this:

cd MyFolder

Get-ChildItem -recurse -filter .DS_STORE | Remove-Item -WhatIf

When you specify -WhatIf, then PowerShell won't make any changes. It will instead tell you what it would have done. When you are happy with what it will do, then you can remove the -WhatIf. (It always pays to be careful when doing a recursive delete. You don't want to delete the wrong things.)

  • Only deletes the first .DS_STORE, not the others in the subdirectory – tarabyte Mar 31 '15 at 3:20
  • @tarabyte, sorry, answer updated. – dangph Mar 31 '15 at 3:39
  • 1
    You might also need to follow it up with gci -recurse -filter "._*" | del -whatif to remove HFS garbage. – Nick T Nov 25 '15 at 22:57

That find syntax you are using in your example seems to me to be more appropriate for Mac OS X or Linux/Unix setups than a Windows setup. Instead, perhaps use the del command like this in Windows as explained here:

del /s /q /f /a:h .DS_STORE
  • I've tried that too and get the error: Remove-Item: A positional parameter cannot be found that accepts argument '/q' from the directory of interest and using Windows PowerShell. – tarabyte Mar 29 '15 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.