Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 16th, 2007, 10:54 AM
ltima_driver ltima_driver is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 ltima_driver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 47 sec
Reputation Power: 0
VBScript - Delete contents of a folder remotely

Hi There,

Well I am making a lab cleanup HTA and am having problems when it comes to a folder that is shared. What I want to is delete all the contents in C:\logs on a remote server.

This is the basic concept of what the script does:

1. Maps to the \\Servername\C$ to drive P:
2. Deletes the folder P:\logs
3. Recreate a logs folder

The problem is that if the logs folder is shared my script fails. Is there anyway I can delete all the contents of C:\logs without deleting the folder? or any other way that I can delete the shared folder, and when I recreate it share it again..?

Thanks in advance

Dhruv

Reply With Quote
  #2  
Old August 17th, 2007, 01:44 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Try something like this...

vb Code:
Original - vb Code
  1. Set objFso = CreateObject("Scripting.FileSystemObject")
  2. Set WshNetwork = CreateObject("WScript.Network")
  3.  
  4. WshNetwork.MapNetworkDrive "P:", "\\Servername\C$"
  5.  
  6. Set objFolder = objFso.GetFolder("P:\logs")
  7. killFiles(objFolder) 'Delete files
  8. doSubfolders(objFolder) 'Delete files in subfolders
  9. Set objFolder = Nothing
  10.  
  11. Sub killFiles (ByRef objFolder) 'Delete all files in folder
  12.     Set colFiles = objFolder.Files
  13.    
  14.     On Error Resume Next
  15.     For Each objFile In colFiles
  16.         objFile.Delete
  17.     Next
  18.     On Error Goto 0
  19. End Sub
  20.  
  21. Sub getSubFolders(ByRef objParentFolder) 'If subfolders exist, process files in each folder
  22.     Set colSubfolders = objParentFolder.SubFolders
  23.     For Each objSubfolder In colSubfolders
  24.         killFiles(objSubfolder)
  25.         If objSubfolder.SubFolders.Count > 0 Then
  26.             getSubFolders(objSubFolder)
  27.         End If
  28.         objSubfolder.Delete
  29.     Next
  30. End Sub
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Last edited by Nilpo : August 24th, 2007 at 07:54 PM.

Reply With Quote
  #3  
Old August 17th, 2007, 09:46 AM
ltima_driver ltima_driver is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 2 ltima_driver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 47 sec
Reputation Power: 0
Thanks for your reply..

I am having problems with the line
Set colFiles = objFolder.Files

It says it dosent recognize objFolder...I have no idea why..

Reply With Quote
  #4  
Old August 24th, 2007, 07:53 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,048 Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)Nilpo User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Days 12 h 32 m 33 sec
Reputation Power: 555
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Quote:
Originally Posted by ltima_driver
Thanks for your reply..

I am having problems with the line
Set colFiles = objFolder.Files

It says it dosent recognize objFolder...I have no idea why..
Oops...add SET

Set objFolder = objFso.GetFolder("P:\logs")

Sorry, had a typo. I've made the change above as well.

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > VBScript - Delete contents of a folder remotely


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT