Automated file deletion #01

————————————————————————————————————-

new-psdrive -name SomeFolder -psprovider FileSystem -root \\SomeShare\SomeFolder
$drive = new-object -com wscript.network
$drive.MapNetworkDrive(“x:”, “\\SomeShare\SomeFolder”)

$EnumerateOpen = Get-ChildItem o:\ -recurse -include .DS_Store -force
foreach($FileName in $EnumerateOpen)
 {
  $FileName.Delete()
 }

remove-psdrive -name SomeFolder

$drive.RemoveNetworkDrive(“x:”)

—————————————————————————————–

As with my previous post, this script does nothing apart from delete irritating files that do nothing apart from waste space. In this case, it’s the lovely .DS_Store files that Mac OS X throws around with glee. I’ve got a feeling you can put loads of file types in one script, but I’ve got a script per file type to (a) make testing easier- didn’t want to risk accidentally wiping out more than I’d intended and (b) to make it easier for others to follow.

Remeber that although your .DS_Store is “only” 7KB in size, it’s probably taking up way more space than that because file systems have minimum block sizes. According to this link- http://support.microsoft.com/kb/140365– any Windows OS from the last 12 years will default to a minimum block size of 4KB, so that 7KB file is already wasting 1KB of space. Multiply that by the number of .DS_Store files lying around and that’s a lot of wasted space. Add in all those accidentally created .lnk files, thumbs.db etc- just bin ’em.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s