Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Delete all but specified subfolders

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1152
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Delete all but specified subfolders
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Delete all but specified subfolders - 7/15/2004 9:22:07 PM   
  Speedy

 

Posts: 8
Score: 0
Joined: 7/7/2004
From:
Status: offline
Hi, I want to run a script which can delete all but the specified local user profiles on Win2K workstations.
The script below only works if I change the <> operators to = and uncomment the commented script, but that adds unnecessary few lines of the script,which I don't want.
Why can't I use more '<>' in IF statement but = is OK? Or is there any other issue I do not know about?
Thanks

Set fs = CreateObject ("Scripting.FilesystemObject")
Set f = fs.GetFolder("C:\Documents and Settings")
Set subf = f.SubFolders
dim z
For Each z in subf
If z.Name <> "Administrator" or z.Name <> "All Users" or z.Name <> "Default User" Then
'WScript.Echo "can't delete folder " & z.Name
'Else
z.Delete True
End If
Next
Set fs = Nothing
 
 
Post #: 1
 
 Re: Delete all but specified subfolders - 7/16/2004 12:16:55 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
You can use multiple <> in a single if statement, I have done it before. One thing to keep in mind, is that it is case sensitive. So try something like this:

If lcase(z.Name) <> "administrator" or lcase(z.Name) <> "all users" or lcase(z.Name) <> "default user" Then

You could also use Select Case

Select Case lcase(z.name)
Case "administrator"
WScript.Echo "can't delete folder " & z.Name
Case "all users"
WScript.Echo "can't delete folder " & z.Name
Case "default user"
WScript.Echo "can't delete folder " & z.Name
Case Else
Delete folder
End Select

(in reply to Speedy)
 
 
Post #: 2
 
 Re: Delete all but specified subfolders - 7/19/2004 9:47:50 PM   
  Speedy

 

Posts: 8
Score: 0
Joined: 7/7/2004
From:
Status: offline
Thanks mate,
I'll try that.
Speedy

(in reply to Speedy)
 
 
Post #: 3
 
 Re: Delete all but specified subfolders - 8/2/2004 8:09:51 PM   
  MABU

 

Posts: 2
Score: 0
Joined: 7/12/2004
From: United Kingdom
Status: offline
You may also want to change the "or" to "and" in your IF statement otherwise your logic will always work out TRUE and therefore delete everything.

Regards,

M.

(in reply to Speedy)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Delete all but specified subfolders Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts