简体   繁体   English

vbscript-错误恢复,“权限被拒绝”

[英]vbscript — on error resume with a “permission denied”

I have a script that scans subdirectories recursively and deletes files older than X date. 我有一个脚本,该脚本以递归方式扫描子目录并删除早于X日期的文件。 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语句时,会发生问题。

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. 似乎尽管脚本无法删除文件或获取文件夹的内容会引发错误,但Err.Number并没有增加。 Is there a better way to go about doing this? 有没有更好的方法可以做到这一点?

The problem is likely due to this comparison Err.Number > 0 . 该问题可能是由于此比较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 . 您应该使用Err.Number <> 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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