Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

DELETE FOLDER EXCEPT SUBFOLDERS...

Posted 23 Apr 2004 17:15:45
1
has voted
23 Apr 2004 17:15:45 A B posted:
Hi there, this is not so much an ASP question although a VBScript one, does anyone know how to code a vbscript so that it looks at a folder and deletes all the subfolders apart from specied ones??
Thanks.

Replies

Replied 24 Apr 2004 17:26:12
24 Apr 2004 17:26:12 Phil Shevlin replied:
This deletes files of a specific extension, but if you alter it to look for "Not Folder" then it should work...

aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=176
Replied 26 Apr 2004 11:37:00
26 Apr 2004 11:37:00 A B replied:
Hmm bit confusing for a beginner like me? I dont see how using not folder would work? See I have subfolders in a directory e.g:- c:\Profiles\, now some Profile folders are created when a new user logs on, i.e - c:\Profiles\jim\. might be created. also the direcotry may have default folder i.e:- c:\Profile\bob\. so how can i code it to delete all the folders in c:\Profile\ apart from say c:\Profile\bob\?? remember I would not know the path of the other folders created, only the root dir = c:\Profiles.
Does this clarify my question a little better?
Replied 26 Apr 2004 14:30:16
26 Apr 2004 14:30:16 Vince Baker replied:
using the fileobject cant you just code to delete all where filename <> bob?

Regards
Vince

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 26 Apr 2004 18:29:40
26 Apr 2004 18:29:40 A B replied:
OK, i have created the following code shown below but on line 12 i am getting an error when i try to delete the rest of the folders, the error is a "Permission denied" error, any thoughts on this???

Dim FSObject
Dim FolderObj

Set FSObject = CreateObject("Scripting.FileSystemObject"
Set FolderObj = FSObject.GetFolder("C:\Documents and Settings"

For Each Profile In FolderObj.SubFolders
Select Case UCase(Profile.Name)
Case "ADMINISTRATOR", "All Users", "Default User", "SMSCCMBootAcct&", "SMSCliSvcAcct&", "SMSCliToknAcct&"
'Do nothing
Case Else
FSObject.DeleteFolder Profile.Path, True
End Select
Next
Replied 27 Apr 2004 01:23:12
27 Apr 2004 01:23:12 Phil Shevlin replied:
Any folder you wish to write to needs read/write permission. You need to CHMOD the folder to 777:

www.webhostingtalk.com/showthread.php?s=&threadid=227751

However, you appear to be messing with the docs and setting folder -- not a good move.

Edited by - wdglide on 27 Apr 2004 01:24:20

Reply to this topic