Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleteing multiple directories???

Status
Not open for further replies.

ORASYB

MIS
Mar 5, 2003
2
US
Howdy!

I'm somewhat of a newbie to VB Scripting and I'm trying to do what I think is simple but I'm getting stuck. I'm not even sure if a vb script is approriate or necessary to do this. Here's what it want to do;

I want to create a boot time event (XP Event Handler) that will run a vb script to delete all the subdirectories in a given parent directory. For example, if I have a directory on my drive called "Logs" and it contains numerous subdirectories who's names are numnerical and all begin with a 0 like "021243" and "030403" etc...I'm trying to write a script that will check this Logs directory for the existance of these subdirectories and delete them (and all thier contents).

I know I need the following components but I'm not sure if I'm over engineering this. I'm also struggling with the syntax. Any help would be greatly appreciated.

1) check Logs directory for any subdirectories
2) if subdirectories are found delete all of them and their contents
3) if no subdirectories are found then just abort

That's it ;-)

TIA!

-ORASYB


 
Do what you want this way :
Code:
Const LOG_DIR = "C:\LOGS"
Dim Gob_Fso, Gob_LogFolder, Gob_LogSubFoldersCollection, Gob_LogSubFolder

Set Gob_Fso = CreateObject("Scripting.FileSystemObject")
Set Gob_LogFolder = Gob_Fso.GetFolder(LOG_DIR)
Set Gob_LogSubFoldersCollection = Gob_LogFolder.subFolders
For Each Gob_LogSubFolder in Gob_LogSubFoldersCollection
  Gob_LogSubFolder.delete(true)
Next

Cut and paste this code, change the LOG_DIR constant value... and you're on !!! Water is not bad as long as it stays out human body ;-)
 
Thanks Targol!!! I will give this a try later today and let you know how it went. I think I need to invest in a good VB Script reference book for the future. Any suggestions?

Regards,

-ORASYB

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top