[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

VB Script Help

I am running the following script to delete files from a folder upon login.  The script works fine, but the problem is not all users have this folder path.  Is there a way to supress the path not found error?  Applying script to certain GPOs is not an option.

Set objShell = CreateObject( "WScript.Shell" )
strLocalAppData=objShell.ExpandEnvironmentStrings("%LocalAppData%")
strFolder = strLocalAppData & "\Cisco\Unified Communications\Jabber\CSF\Photos"
Set fso = CreateObject("Scripting.FileSystemObject")
For Each objFile In fso.GetFolder(strFolder).Files
'  Wscript.Echo "Deleting file: " & objFile.Path
  objFile.Delete
Next
For Each objSubfolder In fso.GetFolder(strFolder).Subfolders
'  Wscript.Echo "Deleting folder: " & objSubfolder.Path
  objSubfolder.Delete
Next

Open in new window

0
Kram80
Asked:
Kram80
  • 2
1 Solution
 
dustockCommented:
Add On Error Resume Next before you call the delete, if it encounters an error it will continue through the loop.

You can google 'vbscript error handling' for more information
0
 
Kram80Author Commented:
Thanks for the help.  Appreciate it.
0
 
dustockCommented:
No problem
0
 
Bill PrewCommented:
As an alternate you can do this, and not have to disable error checking.

Set objShell = CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.FileSystemObject")
strFolder = objShell.ExpandEnvironmentStrings("%LocalAppData%\Cisco\Unified Communications\Jabber\CSF\Photos")
If fso.FolderExists(strFolder) Then
  For Each objFile In fso.GetFolder(strFolder).Files
  '  Wscript.Echo "Deleting file: " & objFile.Path
    objFile.Delete
  Next
  For Each objSubfolder In fso.GetFolder(strFolder).Subfolders
  '  Wscript.Echo "Deleting folder: " & objSubfolder.Path
    objSubfolder.Delete
  Next
End If

Open in new window

~bp
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now