简体   繁体   English

删除文件时 VBScript 权限被拒绝

[英]VBScript Permission denied when I delete a file

Let me start by saying I am self taught in VBScript.首先让我说我是在 VBScript 中自学的。

I have a folder that gets filled with temporary files and I need to delete them.我有一个充满临时文件的文件夹,我需要删除它们。

So I created a script when it runs I am getting a permission denied when the script tries to delete the file.所以我在运行时创建了一个脚本,当脚本尝试删除文件时,我的权限被拒绝。 I am a Domain Admin, but to be sure I manually deleted a file and had no issues.我是域管理员,但可以肯定的是我手动删除了一个文件并且没有问题。 I get the same message even when I run the script on the server.即使我在服务器上运行脚本,我也会收到相同的消息。

I tried to post all of my code here put I had a hard time reading it.我试图在这里发布我的所有代码,但我很难阅读它。 If you can tell me how to post it so you can read it please let me know.如果你能告诉我如何发布它以便你可以阅读它,请告诉我。 I saw something about putting a ">" on the first line put It was not putting everything on one line.我看到了一些关于在第一行放置“>”的内容 put 这并不是将所有内容都放在一行上。

Here is the section I am having issues with, the error is the last line (Permission Denied)这是我遇到问题的部分,错误是最后一行(权限被拒绝)

Set objFile = objFSO.GetFile(strFolder1 & "\\" & strFileName.Name) objFSO.DeleteFile myFileToDelete, True设置 objFile = objFSO.GetFile(strFolder1 & "\\" & strFileName.Name) objFSO.DeleteFile myFileToDelete, True

OK I looked at help more.好的,我查看了更多帮助。 I could not indent even with 4 spaces in front.即使前面有 4 个空格,我也无法缩进。 Not sure how to code this, I tried but I cannot get it to accept it.不知道如何编码,我试过了,但我无法接受它。

TIA, Rodger TIA,罗杰

This should do what you're asking:这应该做你要问的:

Sub DeleteMyFile(myFileToDelete)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.DeleteFile(myFileToDelete)
End Sub

myFileToDelete = strFolder1 & "\" & strFileName
DeleteMyFile(myFileToDelete)

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

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