权限被拒绝的DeleteFile [英] DeleteFile with Permission Denied
问题描述
我遇到了一个问题,该问题在Stack Overflow上有很多条目,但是没有一个解决了我的问题.
I'm running into and issue that has many entries on Stack Overflow, but none of them solved my problem.
我有这段代码,试图删除文件夹中的每个.txt,但是我在"DeleteFile"命令上始终遇到权限被拒绝的错误:
I have this piece of code, which tries to delete every .txt in a folder, but I keep getting a permission denied error on the "DeleteFile" command:
directory = "C:\TEST\FOLDER"
Set fso = CreateObject("Scripting.FileSystemObject")
Function DeleteTXTs
For Each f In fso.GetFolder(directory).Files
If LCase(fso.GetExtensionName(f)) = "txt" Then
fso.DeleteFile("C:\TEST\FOLDER\*.txt"),DeleteReadOnly
End If
Next
End Function
我对"C:\ TEST"和子文件夹的权限完全控制于Windows中存在的每个帐户...我该怎么办?
My permissions on the "C:\TEST" and subfolders are of full control to every account that exists in windows... What could I do?
推荐答案
我已经测试了代码,并且可以正常工作,是否值得在的
循环,因为它可能是导致问题的特定文件.第二个测试是您是否正确声明了 On Error Resume Next
错误处理中添加For DeleteReadOnly
,因为当我从代码中删除此代码时,当代码到达只读的.txt文件时,我还收到了权限被拒绝"的信息.最后,如果您更改了文件夹的权限,是否可以执行旧的忠实重启.
I have tested the code and it works correctly, is it worth adding in On Error Resume Next
error handling in the For
loop, as it may be a specific file that is causing the problem. A second test would be have you declared the DeleteReadOnly
correctly as when i removed this from the code i also received a "permission denied" when the code reached a read only .txt file. Finally if you have changed permissions on a folder have you done the old faithful reboot.
这篇关于权限被拒绝的DeleteFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!