删除权限被拒绝的文件 [英] 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:TESTFOLDER"
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:TESTFOLDER*.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
错误处理ForDeleteReadOnly
,因为当我从代码中删除它时,当代码到达只读 .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.
这篇关于删除权限被拒绝的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!