Thursday, May 7, 2009

Deleting Files = Watching Grass Grow

Deleting files is such a tedious chore. But what really gets me is how different people approach the challenge. If you ask five IT goofballs how to delete files, you will almost certainly get five different answers. Actually, using IT goofball math, you'll probably get seven different answers.

Here's a tip: Each time the IT goofball responds with "well, I would..." or "you should..." just keep walking. The first person that responds with "What exactly are you trying to do?" is the one you should pay attention to.

The most common problem I see within the human realm of technology, is that whenever a question is asked (a challenge is announced), the techno-nerds knee-jerk with answers, "solutions", "ideas", and so on. The result is almost always shooting in the wrong direction and missing the target. I always ask questions in return. It almost ALWAYS begins a dialog which eventually unveils an entirely different problem that REALLY needs to be solved.

Case in Point: "How can I delete a given file from every computer on our network?"

Likely responses:

"You could write a script"
"You could use a shareware/freeware app named ____"
"You could ..."

Proper responses:

"Why?"
"How did the file get on all the computers?"

In the end, you might discover that the problem isn't the file at all. It might be some other process or program which is spewing it out, which would be an endless job of mopping it up. Or it might be a file that actually needs to be left alone. Or it might actually be a complete misunderstanding and nothing needs to be done at all.

If you knee-jerk and start writing a script or downloading shareware tools, you could be wasting hours of valuable time. You might delete the file and find out you created an even-bigger problem.

But, just because I have to do something stupid...

Const filename = "foobar.txt"
Const domain = "MyCompany"

Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Wscript.Shell")
Set objDomain = GetObject("WinNT://" & domain)
For each objX in objDomain
If Lcase(objX.Class) = "computer" Then
strComputer = objX.Name
strPath = "\\" & strComputer & "\c$"
If fso.FolderExists(strPath) Then
cmd = "cmd /c del /s /f /q " & strPath & "\" & filename
shell.Run(cmd, 1, True)
Else
Wscript.Echo strComputer & " is offline"
End If
End If
Next
Set shell = Nothing
Set fso = Nothing


Disclaimer: If you don't test this in a "safe" environment before running it in a production environment, you are an idiot. If you use this malicously or cause any damage or disruption to anyone or any environment, you assume all responsibility and liability, culpability, and jailability.
Post a Comment