Solved

VB Script Help

Posted on 2013-01-17
4
279 Views
Last Modified: 2013-01-17
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
Comment
Question by:Kram80
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 250 total points
ID: 38788383
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
 

Author Comment

by:Kram80
ID: 38789083
Thanks for the help.  Appreciate it.
0
 
LVL 9

Expert Comment

by:dustock
ID: 38789193
No problem
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 38790030
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question