-1

I am trying to delete the temporary files created in C:\Users\xxxxxx\AppData\Local\Temp using vbscript.

santosh
  • 89
  • 4
  • 11

1 Answers1

0

The best way would be to leverage robocopy... but if it must be done in vbscript... here's a simple method.

The run method below will execute hidden from the user interface.

Set fso = CreateObject("Scripting.FileSystemObject")
Set oshell = CreateObject("WScript.Shell")
EmptyFolder=oshell.ExpandEnvironmentStrings("%userprofile%") & "\Empty"

if NOT (fso.folderexists(EmptyFolder)) Then fso.CreateFolder(EmptyFolder)

oShell.run "robocopy ""%userprofile%\Empty"" ""%tmp%"" /purge", 0, true

if (fso.folderexists(EmptyFolder)) Then fso.DeleteFolder(EmptyFolder)
Steve Kline
  • 805
  • 4
  • 11