סקריפט למחיקת קבצים ישנים, בעלי סיומת נתונה

May 24, 2011

tags: ,
no comments

 Dim fso, foldername, filenametodelete


Set fso = CreateObject(“Scripting.FileSystemObject”)
Set foldername = fso.GetFolder(“C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\”)
For each filenametodelete in foldername.Files
     if datediff(“d”, filenametodelete.DateLastModified, now()) >3 and right(filenametodelete.Path, 4) = “.trc” then
     fso.DeleteFile filenametodelete.Path
    End If
On Error Resume Next
 Next


 


The script using a few steps:



1. The script access to “C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\”
2. The script check if files with *.trc extension exits.
3. If files with *.trc extension was found, it check if the time difference between the creation data to the current time is more than 3 days.
4. If step 3 is correct, the files are deleted.


 

Add comment
facebook linkedin twitter email

Leave a Reply