I agree ... my bad ... for those who did not get it.

This is a vbs script.

~~~~~~~~~~start script~~~~~~~~~~~

'~~[script]~~

' Script to delete all files older than a specified days w/detail logging
' Added provision for up to 10 filters on delete.
' Specify the date range, filter info and whether you
' want to actually delete the files.
'  Created - 02/18/2003 Christopher Checca

Option Explicit
Dim WSHShell, fs, Header, LogFile, LogName
Dim PCName, FilePath, File
Dim FDate, Count, DelCount, AllFilters, OlderThan
Dim DoDelete, ObjDirectory, TheFiles
Dim TimeIt, EndTime, StartTime
Dim FilterList(10)

Const ForReading = 1, ForWriting = 2

Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Header = WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
PCName = WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Count = 0
DelCount = 0
AllFilters = 10
StartTime = Timer

' changeable Settings
LogName = "c:\DEFAULTLOG.LOG"


' Dont actually Delete the files, just log the ones that meet the criteria
' Change this to do the delete (TRUE = do it! or FALSE = don't do anything!)
DoDelete = FALSE


' path to start from and search anything below that
FilePath = "\\SERVER\Backup"
' ex: C:\TEMP

' date "olderthan" to delete
OlderThan = (Now() - (10)) ' older than 10 days

' File and directory filters  
' Populate FilterList
FilterList(1) = UCase("pagefile.sys")       ' system file
FilterList(2) = UCase(".dll")               ' system file
FilterList(3) = UCase(".exe")               ' dont delete any program files

   

'*****[ Script begin ]**************
' You can remove this POPUP if you are running this from cron
' WSHShell.Popup "Searching for Files Older than = " & CStr(OlderThan), 5,
Header, 64

' Open log file
StartLogging()
StartTime = Now()
LogEvent(" Searching for Files Older than = " & OlderThan)
LogEvent("  From " & FilePath & " on " & PCName & " @ " & Now())
Set ObjDirectory = fs.GetFolder(FilePath)
If NOT DoDelete Then
  LogEvent("   Files will not be Deleted.")
End If


' main subroutine
 Process ObjDirectory


LogEvent(" Total Files Counted = " & CStr(Count))
If DoDelete Then
  LogEvent(" Total Files Deleted = " & CStr(DelCount))
End If
EndTime = Timer
TimeIt = EndTime - StartTime
StopLogging()
Set fs = Nothing
' You can remove this POPUP if you are running this from cron
' WSHShell.Popup "Deleted files ... Completed.", 5, Header , 64
WshShell.LogEvent 0, "DEFAULT - deleted files = " & CStr(DelCount)
wscript.Quit

 
' EOS '*******************
'*************************
'*************************

Sub RemoveFile(TheFile)
 Dim oFile
 DelCount = DelCount + 1
 Set oFile = fs.GetFile(theFile)
  on error resume next
 oFile.Delete
 LogEvent(TheFile & " -Deleted")
End Sub 'RemoveFile()


Function InFilter(AFile)
  Dim Z, TmpStr
  InFilter = FALSE
   For Z = 1 to AllFilters 
     TmpStr = CStr(FilterList(Z))
    If (Instr(UCase(AFile), TmpStr)> 1) Then
        InFilter = TRUE
    End If
  Next             
End Function 'InFilter


Sub Process(objDirectory)
 Dim MoreFolders, TempFolder
  Set TheFiles = objDirectory.Files

     For Each file in theFiles
            Count = Count +1        
            If FExist(File.Path) Then        
               IF NOT InFilter(File.Path) Then
                 FDate = GetFileDate(File.Path)
                 If (FDate < OlderThan) Then
                    If DoDelete Then
                      RemoveFile(File.Path)
                    Else
                      LogEvent(File.Path & " - " & FDate & " To Delete.")
                    End If
                 End If 
               End If            
            End If
        Next

 Set MoreFolders = objDirectory.SubFolders

 For Each TempFolder In MoreFolders
  Process TempFolder
 Next
End Sub   'Process()

Function GetFileDate(theFile)
  Dim oFile
  Set oFile = fs.GetFile(theFile)
  GetFileDate = oFile.DateLastModified
End Function 'GetFileDate()

Sub LogFileInfo()
' LogEvent(File.Path & " : " & FDate & ":   Is Older Than " & OlderThan)
 LogEvent(File.Path & " - " & FDate)
End Sub 'LogFileInfo()

Sub StartLogging()
On Error Resume Next
Set LogFile = fs.CreateTextFile(LogName,vbTrue)
 If (Err.Number <> 0) Then
     WSHShell.Popup "Could not create log file " & LogFile, 2, Header, 0
     Wscript.Quit(1)
 End If
LogFile.WriteLine " Logging Enabled : " & Now()
ScriptLoc = wscript.scriptfullname
LogFile.WriteLine " Script running from : " & ScriptLoc
End Sub 'StartLogging()

Sub StopLogging()
  On Error Resume Next
  LogFile.WriteLine " Logging Disabled : " & Now()
  LogFile.Close
End Sub

Sub LogEvent(StringtoWrite)
  on error resume next
  LogFile.WriteLine StringtoWrite
End Sub

Sub LogEventNoCR(StringtoWrite)
  on error resume next
  LogFile.Write StringtoWrite
End Sub

Sub show_msg(strText)
    MsgBox strText, vbInformation, Header
End Sub

Function FExist(filespec)                 ' File Exists
  FExist = FALSE
  If (fs.FileExists(filespec)) Then
    FExist = TRUE
  End If
End Function

~~~~~~~~~~~end script~~~~~~~~~~~~

Christopher A Checca
IT Department
Packard Transport, Inc.
24021 South Municipal Drive
Channahon, IL.  60410-9788
815-467-9260
413-723-3753 fax
mailto:[EMAIL PROTECTED]
www.packardtransport.com
 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of John Tolmachoff
(Lists)
Sent: Thursday, October 23, 2003 10:31 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: [IMail Forum] Sending attachments to the list!
Importance: High

It is not generally a good idea to send attachments other than txt or zip to
the list.

NEVER send known executable attachments, such as exe or vbs to the list, as
many of us completely block messages with those types of attachments.

John Tolmachoff
Engineer/Consultant/Owner
eServices For You



To Unsubscribe: http://www.ipswitch.com/support/mailing-lists.html
List Archive: http://www.mail-archive.com/imail_forum%40list.ipswitch.com/
Knowledge Base/FAQ: http://www.ipswitch.com/support/IMail/


To Unsubscribe: http://www.ipswitch.com/support/mailing-lists.html
List Archive: http://www.mail-archive.com/imail_forum%40list.ipswitch.com/
Knowledge Base/FAQ: http://www.ipswitch.com/support/IMail/

Reply via email to