A PHP script for removing Thumbs.db, .DS_Store, MacOS hidden and other annoying files +

Tired of explaining to others how to turn off thumbnail caching on Windows, how to install TinkerTool on Mac? Deleted your fair share of those damn files manually? Me too! Never again!

/**
* housekeeping.php
*
* Removes various annoying hidden and/or useless files leftover from
* different people doing different stuff on the filesystem using
* various OSes.
*/

Source: housekeeping.php (5KB, .phps file)

When and how you invoke the function (cron or scheduled tasks, manually, before/after/during some scm process, on login/logout…) is up to you.

Questions, comments, etc — use the form below. Enjoy nuking those files.

13 Responses to “A PHP script for removing Thumbs.db, .DS_Store, MacOS hidden and other annoying files”

  1. Thnx, works like a charm :)

  2. I have downloaded the housekeeping.php file how to run this in windows it asking me program to open

    help plz

    Syed

  3. @syed:
    this is an excerpt from the comments from the file you downloaded:

    * @usage rdir_cleanup(‘.’); // just a ‘test-run’ in the current working dir
    * @usage rdir_cleanup(‘.’, true); // nuke everything from the cwd and further below

    So, housekeeping.phps just gives you a function, that you can use in your own php script, that is yet to be writtten (and ran after that) by you. To do that on a default Windows box, you’ll probably have to do all or some of these steps:

    step 1: download and install php so you can run php scripts on your computer
    step 2: open go to the folder where you saved housekeeping.phps and rename it to housekeeping.php
    step 3: open housekeeping.php with a text editor and add one extra line to the bottom (call the rdir_cleanup() function with parameters that suit you)
    step 4: fire up command prompt (Win+R, type in cmd, hit enter), go to the folder where housekeeping.php is, and now finally type “php housekeeping.php” (without quotes) in the command-line — that runs the script.

    Steps 2-4 could maybe be avoided by installing php with a windows installer that automagically assigns .php files to the php interpreter, so you could maybe just double-click .php files in windows explorer to run them. Haven’t tried it tho.

  4. Very useful! Thanks

  5. Could I upload this to my shared webhost and run it? I compressed a bunch of files/folders from my Mac, uploaded and extracted the zip archive online, and now my site’s folders are littered with .DS_Store files..

    Thanks!

  6. @suk: Yep. Just read comment #3 and act accordingly. Standard disclaimers still apply :)

  7. awesome.. it worked. just a tiny suggestion, to output a br tag after each line so it’s easier to read the output. :)

    great script, and thanks again!

  8. @suk: Thanks for the comments. New version of the script is uploaded to the link above (http://zytzagoo.net/code/housekeeping/housekeeping.phps), this one should output <br/> tags if you’re running it through a web server.

  9. Brilliant, Client security scans were coming back with ._DS’s. I was freaking out at the thought of going through 500+ folders on the server and deteling each list of invisibles separately.
    Awesome. Awesome. Awesome.

  10. Hey,

    Looks like just the script I need.

    “Out of the box” does this scan and delete all the .DS_Store thumbs.db files recursively without having to edit the php file?

  11. @David: The file itself only provides a PHP function named rdir_cleanup(). You’ll need to call the function yourself (and provide the adequate parameters).

  12. @ZYTZAGOO

    Can you give me an example.
    I’m running a Linux web server, I’ve uploaded the file to my server’s root, but how can I just run it to clear all the files recursively?

    Dave.

  13. @Zytagoo

    Scratch my last comment.

    It’s literally a case of adding dir_cleanup(‘.’ true); to the end of the file to do this.

    Thanks for the Script