Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

vbscript: An error was encountered (-2147024894 - )

%SystemRoot%\$blabla$ - if older then 30 days, then delete:
Set objRE = New RegExp
With objRE
	.Pattern    = "^(\$)(.*\$)$"
	.IgnoreCase = True
	.Global     = True
End With
Set oSystemRoot = oFSO.GetFolder(sSystemRoot)
For each folder In oSystemRoot.SubFolders	
	If objRE.Test(folder.Name) Then
		If DateDiff("d",folder.DateCreated,oDate) >= 30 Then 
			oFile.WriteLine "Deleting " & folder.Path '& " " & DateDiff("d",folder.DateCreated,oDate)'& " with created date: " & folder.DateCreated
			oFSO.DeleteFolder folder.Path, True
			If Err.Number <> 0 Then
				oFile.WriteLine "    An error was encountered (" & Err.Number & " - " & Err.Description & ")"
			End If
		End If
	End If
Next

Open in new window


Output example:
Deleting C:\WINDOWS\$NtUninstallKB982316$
    An error was encountered (-2147024894 - )

What error is this? I can't find information about it. The path is deleted successfully.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

try this:
Dim fso, WshShell 
Dim oFolder, oSubFolder

Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell=CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

Path = WinDir

Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
        If Left(oSubFolder.Name,1) = "$" Then 
                If Right(oSubFolder.Name,1) = "$" Then 
                           'If DateDiff("d", oSubFolder.DateCreated,Now) >= 30 Then
                                fso.DeleteFolder(oSubFolder, True)
                        'End If
                End If
        End If
Next

Set oSubFolder = Nothing
Set oFolder = Nothing
Set fso = Nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of itnifl
itnifl
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So the folders were deleted?
Avatar of itnifl

ASKER

They were always deleted, as stated in the question. It was just the error messages appearing all the time that bothered me. It went away after i started using Err.Clear so that the next Error check not was affected by an old error.
Avatar of itnifl

ASKER

Accepting my own answer in this case..