Hello,
I'm new to vbs. I edited an existing script for what I need, it works great. It deletes any file named 'state' from the user's temp folder & sub folders if found. The state files get recreated, and need to be deleted periodically.
But how can i get this script to run in a loop continuously? So that when the files are created again, they get deleted.
I've tried different loop commands, but can't get it to work.
---
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oshell = CreateObject("WScript.Shell")
TempFolder=oshell.ExpandEnvironmentStrings("%userprofile%") & "\appdata\local\temp"
ShowSubFolders objFSO.GetFolder(TempFolder)
Sub ShowSubFolders(Folder)
For Each file In Folder.Files
Set objCurFile = objFSO.GetFile(file)
If Instr(ucase(objCurFile.Name), UCase("state")) Then objCurFile.Delete
Next
For Each Subfolder in Folder.SubFolders
ShowSubFolders Subfolder
Next
End Sub
I'm new to vbs. I edited an existing script for what I need, it works great. It deletes any file named 'state' from the user's temp folder & sub folders if found. The state files get recreated, and need to be deleted periodically.
But how can i get this script to run in a loop continuously? So that when the files are created again, they get deleted.
I've tried different loop commands, but can't get it to work.
---
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oshell = CreateObject("WScript.Shell")
TempFolder=oshell.ExpandEnvironmentStrings("%userprofile%") & "\appdata\local\temp"
ShowSubFolders objFSO.GetFolder(TempFolder)
Sub ShowSubFolders(Folder)
For Each file In Folder.Files
Set objCurFile = objFSO.GetFile(file)
If Instr(ucase(objCurFile.Name), UCase("state")) Then objCurFile.Delete
Next
For Each Subfolder in Folder.SubFolders
ShowSubFolders Subfolder
Next
End Sub