vbs - 800a0046 - Ignore running files and folders.

omar.rzr 21 Reputation points

I need to clear Caches: files and folders.
But sometimes there are files and folders that are in use, I think this produces the error: “800a0046” permission denied.
I want that if a file or folder is in use, the code will skip it and continue with the next one files and folders.
I accept alternatives.
(Excuse my google english)


Set objFSO = CreateObject("Scripting.FileSystemObject")  
rute1 = "C:\Windows\Temp\"  
rute1existe = objFSO.FolderExists(rute1)  
if (rute1existe) then  
 Const DeleteReadOnly = TRUE  
 objFSO.DeleteFile rute1 & CurrentDirectory & "\*", DeleteReadOnly  
 'objFSO.DeleteFolder rute1 & CurrentDirectory & "\*", DeleteReadOnly  
 msgbox "error"  
end if  


vbs - 800a0046 - Ignorar archivos y carpetas que se encuentren en ejecución.

Necesito borrar Caches: archivos y carpetas.
Pero a veces existen archivos y carpetas que se encuentran en uso, creo que esto produce el error: “800a0046” permission denied.
Quiero que si un archivo o carpeta se encuentra en uso, el código lo salte y continúe con los siguientes archivos y carpetas.
Acepto alternativas.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,762 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 49,071 Reputation points

    In VBS, to handle errors you'll need to use On Error Resume Next.

       On Error Resume Next  
          Do something that can fail  

    If you want to actually do some processing on error then you'll need to use a label.

       On Error Resume HandleError  
          Do something that can fail  
          Do something in case of failure  
       Resume Next  

    For deleting files that may be in use note that if you attempt to delete the entire folder then it'll fail but some files may already be deleted. If you want to delete as many files as you can then you'll need to enumerate the files instead (including their subfolders). For that you'll need to walk all the child folders in the parent folder and then enumerate all the files in each child folder (and they can recursive indefinitely). For each file try to delete it. If a folder is empty then you can remove the folder itself otherwise the folder remains and you move on to the next folder.

    Here's a link to a Stack Overflow post where a person has provided that code. They even seem to have the error handling code in place although I don't know if you need the calls to Echo yourself.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful