Perl: delete_DS_Store

By Xah Lee. Date: .

Here's a perl script that delete those .DS_Store or Thumbs.db etc temp files.

# -*- coding: utf-8 -*-
# perl
# File name:
# Purpose: delete those .DS_Store or Thumbs.db etc temp files.
# created: 2009-05-31, 2013-05-12
# home page:

# To list files that will be deleted, do:
#  perl /Users/xah/Documents/
# To actually delete them, do:
#  perl /Users/xah/Documents/ --delete
# If your path has spaces, you need to quote the path. e.g.
#  perl "/Users/xah/my pictures"

use File::Find;

if (not defined $ARGV[0]) {die qq[Error: argument not received. $0 <dir absolute path> --delete. If the second argument “--delete” is missing, then no deletion will take place, only do report.];}
my $path = $ARGV[0]; # should give a full path, not relative path. Else, the $File::Find::dir won't give full path.


sub wanted {
	if (
      -f $File::Find::name &&
      ($_ eq '.DS_Store' ||
       $_ eq 'Thumbs.db' ||
       $_ eq '.FBCIndex' ||
       $_ eq '.FBCSemaphoreFile' ||
       $_ eq '.localized')
      ) {
		print $File::Find::name, "\n";
		$sizesum += -s "$File::Find::name"; $filenum++;

		unlink $File::Find::name if ($ARGV[1] eq '--delete');

find(\&wanted, $path);

print "Total files deleted (if --delete is given): $filenum\n";
print "Size saved: $sizesum bytes\n";
print "Done.\n";


Here is a collection of files that are created by OS


Desktop DB
Desktop DF




Text Processing