Solved

VB Script Help

Posted on 2013-01-17
4
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 55

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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 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