Solved

VB Script Help

Posted on 2013-01-17
4
259 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
Comment Utility
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
Comment Utility
Thanks for the help.  Appreciate it.
0
 
LVL 9

Expert Comment

by:dustock
Comment Utility
No problem
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now