SunQuest
 
           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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old December 6th, 2006, 01:35 AM
Ringo Ringo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Holland
Posts: 5 Ringo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
VBScript - Delete files/folders automatically

Hi,

At my company we use a shared dump folder which should be emptied every Friday afternoon.
Does anyone know a script witch takes care of this?
It should delete everything in the folder (files/folders) except for the folder itself because this is a share.

Thanks in advance

Ringo

Reply With Quote
  #2  
Old December 6th, 2006, 01:50 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,178 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Weeks 2 Days 6 h 45 m 36 sec
Reputation Power: 683
Hi Ringo

this should do the trick
Code:
<%
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("c:\test\")

for each x in fo.files
  fs.DeleteFile("c:\test\" & x.Name)  
next

set fo=nothing
set fs=nothing
%>

put it in a vbs file, and add the file to the windows
scheduler so that it will run automatically each Friday.

hope this helps
__________________
Look! Its a ShemZilla



Reply With Quote
  #3  
Old December 6th, 2006, 01:54 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,178 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Weeks 2 Days 6 h 45 m 36 sec
Reputation Power: 683
after reading your post again, I see
you want to delete the folders as well,
I haven't test it, but this might work:
Code:
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("c:\test\")

for each x in fo.files
  fs.DeleteFile("c:\test\" & x.Name)  
next

for each x in fo.subfolders
  fs.DeleteFolder("c:\test\" & x.Name) 
next

set fo=nothing
set fs=nothing

Last edited by nofriends : December 6th, 2006 at 02:00 AM. Reason: changed code

Reply With Quote
  #4  
Old December 6th, 2006, 02:39 AM
Ringo Ringo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Holland
Posts: 5 Ringo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
Thanks for the quick reply.
When I run the script it gives me the error: "Object required:'Server'
Is there something in the script which i have to customize ?

Reply With Quote
  #5  
Old December 6th, 2006, 02:51 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,178 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Weeks 2 Days 6 h 45 m 36 sec
Reputation Power: 683
just remove the Server.
it should just be CreateObject("Scripting.FileSystemObject")
the above is for ASP, but that change should make it work

Reply With Quote
  #6  
Old December 6th, 2006, 04:02 AM
Ringo Ringo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Holland
Posts: 5 Ringo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
This works great !!
Thanks for your help

Reply With Quote
  #7  
Old December 6th, 2006, 04:09 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,178 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced FolderFolding Points: 92188 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Weeks 2 Days 6 h 45 m 36 sec
Reputation Power: 683
no worries, glad it worked

Reply With Quote
  #8  
Old December 18th, 2006, 12:51 PM
aprodriguez1970 aprodriguez1970 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 1 aprodriguez1970 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by nofriends
no worries, glad it worked


I like this script also, but need it to be able to selectively delete files and folders older than a set number of days. Can you help me with that?

Thanks.

Reply With Quote
  #9  
Old January 8th, 2007, 12:15 AM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 726 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Days 2 h 2 m 11 sec
Reputation Power: 351
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 aprodriguez1970
I like this script also, but need it to be able to selectively delete files and folders older than a set number of days. Can you help me with that?

Thanks.
Based on File Creation date or Last Modified date?
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Reply With Quote
  #10  
Old May 4th, 2007, 08:32 AM
Ringo Ringo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Holland
Posts: 5 Ringo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
Files read only

Quote:
Originally Posted by Ringo
This works great !!
Thanks for your help

I have worked for a couple of months with this script and i have noticed that when a file is "read only" the script doesn't delete the file and stops.
Is it possible that the script also deletes "read only" files and is there a way to be noticed that the script has stopped working (by a log file for example).

Regards Ringo

Reply With Quote
  #11  
Old May 4th, 2007, 09:12 AM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 726 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Days 2 h 2 m 11 sec
Reputation Power: 351
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 Ringo
I have worked for a couple of months with this script and i have noticed that when a file is "read only" the script doesn't delete the file and stops.
Is it possible that the script also deletes "read only" files and is there a way to be noticed that the script has stopped working (by a log file for example).

Regards Ringo
This will allow it to delete read-only files by setting the file's attributes to 0 prior to deleting. The same could be done for 'folder' if necessary.

I've also optimized the code for you. The last example was a bit redundant.
Code:
Dim fs, fo, files, folders, file, folder

Set fs = CreateObject("scripting.filesystemobject")
Set fo = fs.GetFolder("C:\Test")
Set files = fo.Files
Set folders = fo.SubFolders

For Each file In files
	file.Attributes = 0
	file.Delete vbTrue
Next

For Each folder In folders
	folder.Delete vbTrue
Next
As for logging when the script quits....You can log when it ends normal operation, but there's no way to log when it quits from an error unless you have another process monitoring it.

Reply With Quote
  #12  
Old May 7th, 2007, 03:12 AM
Ringo Ringo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Location: Holland
Posts: 5 Ringo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
Thanks "Nilpo" this works great !

Reply With Quote
  #13  
Old May 7th, 2007, 07:51 AM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 726 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1Folding Points: 171032 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Days 2 h 2 m 11 sec
Reputation Power: 351