Vbscript 删除多个文件不起作用

Vbscript delete multiple files does't work

我需要在 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。谢谢你 DanL