Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 DOS utility for file deletion.

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-04-17 : 16:58:28
Does anyone has a script/exe for periodic file deletion, using date comparison?


------------------------
I think, therefore I am - Rene Descartes

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-04-17 : 17:49:22
Here is a VB Script that I think does something like what your want.

Feel free to test to make sure is is not deleting the stuff you really want to keep, like your database files.

Option Explicit

Const filePath = "D:\MyDirectory\LOG\"

main

Sub Main()
ClearArchive
End Sub

Sub ClearArchive()
Dim fso 'As Scripting.FileSystemObject
Dim fld 'As Scripting.Folder
Dim f 'As Scripting.File

Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(filePath)

For Each f In fld.Files
If Right(LCase(f.Name), 4) = ".txt" Then
If DateDiff("d", f.DateCreated, Date()) > 30 Then
fso.DeleteFile f
End If
End If
Next

Set fld = Nothing
Set fso = Nothing
End Sub


CODO ERGO SUM
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-04-18 : 13:38:11
I am going to put the above code in a .vbs file and call from a batch file. Is there a beter way?

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-04-18 : 14:17:14
You can put it into an ActiveX Script step in a SQL Server Agent job.

Or you could put the code into an ActiveX Script task in a DTS package.




CODO ERGO SUM
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-04-18 : 14:20:00
Thanks MVJ!

I will probably go for SQL JOB. Thanks again.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tfountain
Constraint Violating Yak Guru

491 Posts

Posted - 2008-04-18 : 15:23:25
Ironically there is another post today regarding this topic. I kinda like this suggestion myself - http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101285.
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-04-18 : 15:53:28
Thanks tfountain!

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

dholland
Starting Member

11 Posts

Posted - 2008-04-18 : 19:32:08
Were you able to get this to work like you wanted? I do this a few different ways on several servers... So if you need further help be sure to say so!
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-04-21 : 09:16:24
Thanks dholland! I am thinking of using FORFILES, i will be implementing this is 1-2 days. I will update my findings.


------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-04-21 : 15:16:48
Successfully implemented FORFILES. I guess I don't need other solutions for the time being. Thanks guys.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page
   

- Advertisement -