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

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 October 14th, 2004, 02:32 PM
csillagyitzik csillagyitzik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 39 csillagyitzik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 49 m 40 sec
Reputation Power: 4
Automatic file delete

Hello,
Is there a program that can automatically (schedule) delete files from a certain folder? based on the file creation date (e.g. delete all files that are older then 7 days)?

or - is it easy enough to program a service to do so?

10x

Reply With Quote
  #2  
Old October 19th, 2004, 01:23 PM
JamesLe JamesLe is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Oakland, CA, USA
Posts: 131 JamesLe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m
Reputation Power: 4
Hello csillagyitzik,

Try to setup the Scheduled Tasks for the VBScript below. Hope it will help.

WARNING!!!: Make sure to backup your source folder before testing. This script won't place your files into Recycle Bin. Since this script base on date created of the file, you should test to delete your files from its original location. If you copy your files to another location the date created will change to the current date then no file match with your criteria to delete.

'-------------- CleanUp.vbs --------------------
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("C:\Test") '<----- Change this folder name to match with your case.
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If
For Each srcFile in srcFolder.Files
If DateDiff("d", Now, srcFile.DateCreated) < -7 Then
fso.DeleteFile srcFile, True
End If
Next
Wscript.Echo "Files Deleted successful"
End Sub
'-----------------------------------------------

Reply With Quote
  #3  
Old September 13th, 2005, 08:31 PM
jabbasi jabbasi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 1 jabbasi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m
Reputation Power: 0
delete files on hourly basis

Hi James

following script you put here is really good, and it works, but I have little problem of my own.
that I need to delete log files on hourly basis instead of Day basis, I am Zero in VB.
I thought with small changes like DateDiff > TimeDiff and DateCreated > TimeCreated< I might get it working.
But it didn't work.
Is there anyway I can make this script to delete files ina folder which are more than 2 hours old and send output to a text file.

Your help will be much appreciated.
Sincerely
Jawed Abbasi
Jabbasi@yahoo.com



Quote:
Originally Posted by JamesLe
Hello csillagyitzik,

Try to setup the Scheduled Tasks for the VBScript below. Hope it will help.

WARNING!!!: Make sure to backup your source folder before testing. This script won't place your files into Recycle Bin. Since this script base on date created of the file, you should test to delete your files from its original location. If you copy your files to another location the date created will change to the current date then no file match with your criteria to delete.

'-------------- CleanUp.vbs --------------------
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("C:\Test") '<----- Change this folder name to match with your case.
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If
For Each srcFile in srcFolder.Files
If DateDiff("d", Now, srcFile.DateCreated) < -7 Then
fso.DeleteFile srcFile, True
End If
Next
Wscript.Echo "Files Deleted successful"
End Sub
'-----------------------------------------------

Reply With Quote
  #4  
Old November 14th, 2005, 02:12 PM
JamesLe JamesLe is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Oakland, CA, USA
Posts: 131 JamesLe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m
Reputation Power: 4
Hello Jabbasi,

Sorry for a late response. Just modify the DateDiff function as below to delete files in a folder which are more than 2 hours old.


Code:
...
For Each srcFile in srcFolder.Files
If DateDiff("h", Now, srcFile.DateCreated) < -2 Then
fso.DeleteFile srcFile, True
End If
Next
...



Quote:
Originally Posted by jabbasi
Hi James

following script you put here is really good, and it works, but I have little problem of my own.
that I need to delete log files on hourly basis instead of Day basis, I am Zero in VB.
I thought with small changes like DateDiff > TimeDiff and DateCreated > TimeCreated< I might get it working.
But it didn't work.
Is there anyway I can make this script to delete files ina folder which are more than 2 hours old and send output to a text file.

Your help will be much appreciated.
Sincerely
Jawed Abbasi
Jabbasi@yahoo.com

Reply With Quote
  #5  
Old June 27th, 2006, 06:27 AM
Waaaah Waaaah is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 5 Waaaah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 55 sec
Reputation Power: 0
Smile Automatic file delete

Quote:
Originally Posted by JamesLe
Hello csillagyitzik,

Try to setup the Scheduled Tasks for the VBScript below. Hope it will help.

WARNING!!!: Make sure to backup your source folder before testing. This script won't place your files into Recycle Bin. Since this script base on date created of the file, you should test to delete your files from its original location. If you copy your files to another location the date created will change to the current date then no file match with your criteria to delete.

'-------------- CleanUp.vbs --------------------
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("C:\Test") '<----- Change this folder name to match with your case.
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If
For Each srcFile in srcFolder.Files
If DateDiff("d", Now, srcFile.DateCreated) < -7 Then
fso.DeleteFile srcFile, True
End If
Next
Wscript.Echo "Files Deleted successful"
End Sub
'-----------------------------------------------


hiya pals,

errr.. can i make a request on this? can you make this script silent delete, with no prompt at all? cuz i want to delete folders, cud i not delete the whole folder?

thanks for the reply.
-maester

Reply With Quote
  #6  
Old July 17th, 2006, 06:40 PM
jaswindows jaswindows is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 2 jaswindows User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 33 sec
Reputation Power: 0
Can this be modified to only delete files with a specific extension as well?
I.E. I have a bunch of *.txt files I would like to delete using this script.
There are other files in the directory so a mass delete is unacceptable.
Thank you in advance,
J

Quote:
Originally Posted by JamesLe
Hello Jabbasi,

Sorry for a late response. Just modify the DateDiff function as below to delete files in a folder which are more than 2 hours old.


Code:
...
For Each srcFile in srcFolder.Files
If DateDiff("h", Now, srcFile.DateCreated) < -2 Then
fso.DeleteFile srcFile, True
End If
Next
...

Reply With Quote
  #7  
Old July 18th, 2006, 04:40 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,642 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 16 h 33 sec
Reputation Power: 1471
here is the modified script:
Code:
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Call DeleteFiles(fso.GetFolder("C:\Test"), 7, ".txt") '<----- Change this folder name to match with your case.
Sub DeleteFiles(srcFolder, daysCount, strExtension)
	Dim srcFile, filesCount
	filesCount = 0
	If srcFolder.Files.Count = 0 Then
		Wscript.Echo "No File to Delete"
		Exit Sub
	End If
	For Each srcFile in srcFolder.Files
		If DateDiff("d", Now, srcFile.DateCreated) < ((-1)*daysCount) Then
			If (strExtension="") Or (Right(UCase(srcFile.Name), Len(strExtension))=UCase(strExtension)) Then
				fso.DeleteFile srcFile, True
				filesCount = filesCount+1
			End If
		End If
	Next
	Wscript.Echo filesCount & " Files Deleted successfully"
End Sub

Reply With Quote
  #8  
Old July 18th, 2006, 04:41 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,642 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 16 h 33 sec
Reputation Power: 1471
Quote:
Originally Posted by Waaaah
hiya pals,

errr.. can i make a request on this? can you make this script silent delete, with no prompt at all? cuz i want to delete folders, cud i not delete the whole folder?

thanks for the reply.
-maester
just remove the lines with WScript.Echo

Reply With Quote
  #9  
Old July 18th, 2006, 10:44 AM
Waaaah Waaaah is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 5 Waaaah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 55 sec
Reputation Power: 0
uhm, one final request/question? how will i make this script repeat itself, say, every 15 days, or 30 days? i just want to delete a whole folder, with spaces in their names. (without the script counting the files in it..)

thanks Wizard! : )

Reply With Quote
  #10  
Old July 18th, 2006, 10:49 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,642 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 16 h 33 sec
Reputation Power: 1471
via the Schedules Task. in the Scheduled Task Wizard, when adding task or
editing one, you can set such details.

Reply With Quote
  #11  
Old July 19th, 2006, 04:28 AM
marvster marvster is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 1 marvster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 4 sec
Reputation Power: 0
Great script -- what a lifesaver!

Sorry to pile on, but I wonder if I could ask about one more modification: Is it possible to have the script delete all files in the directory, regardless of how old they are? I tried modifying the file but couldn't get the syntax right.

I realize I can change the DateDiff function to use -1 seconds, but was just curious if there's an even cleaner approach.

Thanks much,

Marv

Reply With Quote
  #12  
Old July 19th, 2006, 05:49 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,642 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1Folding Points: 326366 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 16 h 33 sec
Reputation Power: 1471
using the modified code I posted, you can simply give very big number:
Code:
Call DeleteFiles(fso.GetFolder("C:\Test"), -999999, "")

this will delete all files in the folder with minimal change in the code.

Reply With Quote
  #13  
Old July 19th, 2006, 10:45 AM
Waaaah Waaaah is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 5 Waaaah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 55 sec
Reputation Power: 0
Quote:
Originally Posted by Shadow Wizard
via the Schedules Task. in the Scheduled Task Wizard, when adding task or
editing one, you can set such details.


ahm, what about passwords? will it still run without a proper password?

sorry if i am such a dumb-er newb.. : (

Reply With Quote
  #14  
Old July 20th, 2006, 02:01 AM
Shadow Wizard's Avatar