VBS - Delete files and folders from the Recycle Bin - Error 800a0035 and 800A004C

omar.rzr 21 Reputation points
2022-10-14T21:21:06.1+00:00

I'm new, and I need to delete ALL the contents of the recycle bin (files and folders), but at the end of the process I receive the message: 800a0035 “file not found” or 800A004C “path not found.”
UPDATED: I SOLVED IT, I PUBLISH THE CODE

Const RECYCLE_BIN = &Ha&  
  
 Set FSO = CreateObject("Scripting.FileSystemObject")  
 Set ObjShell = CreateObject("Shell.Application")  
 Set ObjFolder = ObjShell.Namespace(RECYCLE_BIN)  
 Set ObjFolderItem = ObjFolder.Self  
  
  
Set colItems = ObjFolder.Items  
For Each objItem in colItems  
 If (objItem.Type = "File folder") Then  
 Else  
 FSO.DeleteFile(objItem.Path)  
 End If  
Next  
  
Set colItems = ObjFolder.Items  
For Each objItem in colItems  
 If (objItem.Type = "File folder") Then  
 Else  
 FSO.DeleteFolder(objItem.Path)  
 End If  
Next  
Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,416 Reputation points
    2022-10-14T22:43:51.217+00:00

    Are you executing the script with "run as administrator"?

    Add "true" to force delete the file.

    objFSO.DeleteFile objItem.Path,true  
      
    

    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/deletefile-method

    0 comments No comments

  2. WhTurner 1,611 Reputation points
    2022-10-15T09:20:25.87+00:00

    The tag "small-basic" is for Technical questions about Microsoft Small Basic, the only text-based programming language and IDE built for students to learn to code

    Please remove the tag "small-basic" as your question in not about Small Basic

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.