"Rj" <> wrote in message
news:1FFF9C6B-FC50-499F-8CA0-...
> hi , everyone I have a script that deletes specific file extension. I now
> wanna run it as a batch file and schedule it. The problem is that at the
> end
> it pops up a message box to report the no files that it deleted. How do I
> remove the msgbox from the script so that it runs fine as a scheduled
> task.
>
> Credit for this script goes to the person who wrote it, not me. I found it
> on some website while looking for it.
>
> Option Explicit
> '****
> '* Delete all files with the extension "cEXT" in
> '* folders under "cFOL" older than "cDAZ" days.
> '****
> '*
> '* Declare Constants
> '*
> Const cVBS = "DeleteOldTmpFiles.vbs"
> Const cLOG = "DeleteOldTmpFiles.log"
> Const cFOL = "C:\temp\"
> Const cDAZ = 90
> Const cEXT = ".tmp"
> '*
> '* Declare Variables
> '*
> Dim strDAT
> Dim intDAZ
> Dim arrFIL()
> ReDim arrFIL(0)
> Dim intFIL
> intFIL = 0
> Dim strFIL
> Dim strFOL
> Dim strLOG
> Dim strMSG
> strMSG = " " & cEXT & " files deleted under " & cFOL
> Dim dtmNOW
> dtmNOW = Now
> '*
> '* Declare Objects
> '*
> Dim objFSO
> '*
> '* Delete_Files()
> '*
> MsgBox Delete_Files(cFOL) & strMSG,vbInformation,cVBS
>
>
> Function Delete_Files(folder)
> Delete_Files = 0
> '*
> '* Process folder
> '*
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> If objFSO.FolderExists(folder) Then
> Call Get_Files(folder)
> '*
> '* Delete Files
> '*
> For intFIL = 1 To UBound(arrFIL)
> strFIL = arrFIL(intFIL)
> objFSO.DeleteFile strFIL, True
> strLOG = strLOG & strFIL & vbCrLf
> Next
> End If
> objFSO.CreateTextFile(cLOG,True).Write(strLOG)
> Set objFSO = Nothing
> '*
> '* Return Results
> '*
> Delete_Files = UBound(arrFIL)
> End Function
>
>
> Sub Get_Files(folder)
> '*
> '* Get Files
> '*
> For Each strFIL In objFSO.GetFolder(folder).Files
> If LCase(Right(strFIL.Name,Len(cEXT)))= cEXT Then
> strDAT = strFIL.DateLastModified
> intDAZ = DateDiff("d",strDAT,dtmNOW)
> If intDAZ > cDAZ Then
> intFIL = intFIL + 1
> ReDim Preserve arrFIL(intFIL)
> arrFIL(intFIL) = folder & "\" & strFIL.Name
> End If
> End If
> Next
> '*
> '* Get Subfolders
> '*
> For Each strFOL In objFSO.GetFolder(folder).SubFolders
> Call Get_Files(strFOL.Path)
> Next
> End Sub
>
The simplest method would be to remove the msgbox statement. It serves no
purpose other than informing you that the file has been deleted.
Instead of re-inventing the wheel with a long-winded script that a novice
might struggle to understand, you could use a different wheel that has been
in use for a long time. Here is an example:
@echo off
set Limit=90
set Source=C:\Temp
set Dest=c:\Temp%random%
robocopy /Mov /MinAge:%Limit% "%Source%" "%Dest%" *.tmp
rd /s /q "%Dest%"
The batch file will move all .tmp files older than 90 days to a temporary
folder before deleting them permanently. You can download robocopy from
here:
http://www.microsoft.com/downloads/d...displaylang=en