VBScript 删除文件夹失败 Error: Permission Denied Code: 800A0046

症状:

1. 运行下面的VBScript脚本,删除某个目录下的所有文件夹:

Set fso = CreateObject("Scripting.FileSystemObject")
Set deleteDir = fso.GetFolder("D:\FTP_Folder\vbScriptTest")   'Set the directory you want to delete
Set subFolders = deleteDir.Subfolders  'Get all the folders in the above directory
Set toBeDeletedFoldersPath = CreateObject( "System.Collections.ArrayList" ) 'Store the paths of the folders that need to be deleted

For Each folder in subFolders
    toBeDeletedFoldersPath.Add folder.path
Next

For Each folderPath in toBeDeletedFoldersPath
    fso.deleteFolder folderPath
Next

 对于某些文件目录能够删除成功,但是对于某些目录却得到如下的运行时错误:

解决方法:

1. 像下面这样在第11行代码末尾加一个参数True,表示强制删除只读文件夹:

Set fso = CreateObject("Scripting.FileSystemObject")
Set deleteDir = fso.GetFolder("D:\FTP_Folder\vbScriptTest")   'Set the directory you want to delete
Set subFolders = deleteDir.Subfolders  'Get all the folders in the above directory
Set toBeDeletedFoldersPath = CreateObject( "System.Collections.ArrayList" ) 'Store the paths of the folders that need to be deleted

For Each folder in subFolders
    toBeDeletedFoldersPath.Add folder.path
Next

For Each folderPath in toBeDeletedFoldersPath
    fso.deleteFolder folderPath, True   'force the deletion of read-only files
Next

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值