1
votes

I need to create 2 txt files in 2 differit folders. Then I need delete both files, but the script only delete first file from first folder.

There is my vbscript code

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
1
Remove the "On Error Resume Next" to see what error you're getting and when. I suspect a "file in use" exception seeing you didn't close the file objects you created. - DanL
"Microsoft VBScript runtime error: Permission denied " - this is the error - Radulescu Alexandru

1 Answers

3
votes

I solve this. I need to close objFile after create files. Thx you DanL