Vbscript删除多个文件不会';行不通

Vbscript删除多个文件不会';行不通,vbscript,delete-file,Vbscript,Delete File,我需要在2个文件夹中创建2个txt文件。然后我需要删除这两个文件,但脚本只删除第一个文件夹中的第一个文件 这是我的vbscript代码 strFile = "\timestamp.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile(source & strFile) Set ob

我需要在2个文件夹中创建2个txt文件。然后我需要删除这两个文件,但脚本只删除第一个文件夹中的第一个文件

这是我的vbscript代码

strFile = "\timestamp.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")


                Set objFile = objFSO.CreateTextFile(source & strFile)
                Set objFile = objFSO.CreateTextFile(destination & strFile)

                Set src = objFSO.GetFolder(source)
                Set dst = objFSO.GetFolder(destination)

                for each f in src.Files
                   On Error Resume Next
                        name = f.name
                        If name = "timestamp.txt" Then
                            f.Delete True
                        End If
                   On Error GoTo 0
                Next
                for each f in dst.Files
                   On Error Resume Next
                        name = f.name
                        If name = "timestamp.txt" Then
                            f.Delete True
                        End If
                   On Error GoTo 0
                Next

我解决这个问题。我需要在创建文件后关闭objFile。Thx您可以删除“出错时继续下一步”以查看出现的错误和时间。看到您没有关闭创建的文件对象,我怀疑出现了“正在使用的文件”异常。“Microsoft VBScript运行时错误:权限被拒绝”-听到这个错误很好,我是否应该为您发布答案?;-)