26 January 2009

Windows PowerShell: FAIL

What I wanted:
find . -name *.class -exec rm {} \;

What I was told would work:
Remove-Item .\* -recurse -include .class

What I would have settled for (if it had worked):

set fso = CreateObject("Scripting.FileSystemObject")
set fileExpr = new RegExp
fileExpr.Pattern = "class$"
fileExpr.IgnoreCase = True
set curDir = fso.GetFolder(".")
CleanDir curDir, fileExpr

Sub CleanDir(Dir, Expr)
for each File in Dir.Files
if Expr.test(File.Name) then
fso.DeleteFile(Dir.Name & File.Name)
end if
next
for each SubDir in Dir.SubFolders
CleanDir SubDir, Expr
next
end sub


What I finally wound up doing:
[In windows explorer]
Right-click on directory->Search
Click in "Enter all or part of the file name" text box, type ".class"
Click "Search"
Wait
Hit Ctrl-A to select all
Hit "Delete"
Wait (for almost a full minute! WTF?)
Click close button.

Apparently they're shooting for a consistent level of difficulty no matter what the task. Replicate an enterprise database? Five minutes. Import it into Excel, flag outliers and print a formatted report? Five minutes. Delete the file after printing? Five minutes...