JustScriptIt
Technical User
I am trying to build a script that eventually deletes tmp, err, files from remote computers.
There are certain directories that Disk Cleanup just cannot touch, especially if these folders are from other programs installed on Windows.
Right now, I'm trying this on my own computer, and it is not deleting the files, even though the script outputs that the file has been deleted!
There are certain directories that Disk Cleanup just cannot touch, especially if these folders are from other programs installed on Windows.
Right now, I'm trying this on my own computer, and it is not deleting the files, even though the script outputs that the file has been deleted!
Code:
Option Explicit
Dim fso
Dim strDir, objDir, strComputer
Dim strArray, strDrive, strRel
Dim objDelFile, strDelete
''''''''''Declare Sub Routines''''''''''
Sub HandleError()
On Error Goto 0
Err.Clear
End Sub
Sub DeleteFiles(pCurrentDir)
Dim aItem, sParentName, sBaseName
On Error Resume Next
For Each aItem In pCurrentDir.Files
If (Err.Number <> 0) Then
HandleError()
Wscript.echo aItem & " cannot be accessed"
Wscript.echo
Else
If fso.GetExtensionName(aItem.Path) = "txt" Then
If Right(fso.GetParentFolderName(aItem.path),1) = "\" Then
sParentName = Replace(fso.GetParentFolderName(aItem.path),"\","")
Else
sParentName = fso.GetParentFolderName(aItem.path)
End If
sBaseName = sParentName & _
"\" & fso.GetBaseName(aItem.path)
'Wscript.echo sBaseName
strArray = Split(sBaseName,":",-1,1)
strDrive = strArray(0)
strRel = strArray(1)
'Create file object
Set objDelFile = CreateObject("Scripting.FileSystemObject")
strDelete = "\\" & strComputer & "\" & strDrive & "$" & strRel
Wscript.echo sBaseName & " will be deleted"
Wscript.echo
'Delete the file
objDelFile.DeleteFile strDelete,true
End If
End If
Next
On Error Resume Next
For Each aItem In pCurrentDir.SubFolders
If (Err.Number <> 0) Then
HandleError()
Wscript.echo aItem & " cannot be accessed"
Wscript.echo
Else
DeleteFiles(aItem)
End If
Next
End Sub
''''''''''End of Sub Routine Declaration''''''''''
Set fso = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
strDir = "d:\windows\temp"
strComputer = "10.234.4.16"
DeleteFiles(objDir)