简体   繁体   中英

vbscript — on error resume with a “permission denied”

I have a script that scans subdirectories recursively and deletes files older than X date. Because permissions are incorrectly set on some folders, I've had to insert an "On Error Resume" into the code as well, where the error occurs.

However, the problem occurs when I do an if statement...

if (Err.Number > 0)
{
  MsgBox("Permission denied on....")
}

It seems that despite the fact that the script throws an error when it can't delete a file or get a folder's contents, Err.Number isn't increasing. Is there a better way to go about doing this?

The problem is likely due to this comparison Err.Number > 0 . The assumption here is that error numbers are postive numbers. However this is actually rarely true. You should be using Err.Number <> 0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM