Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping a sub routine - issue

Status
Not open for further replies.

Tvegas

Technical User
Apr 24, 2018
1
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top