Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: scheduling deletion of specific files from folders

HTVi
TV Discussion Newsgroups

scheduling deletion of specific files from folders
Rj 10/28/2008 6:34:00 AM
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

Re: scheduling deletion of specific files from folders
"Pegasus \(MVP\)" <I.can[ at ]fly.com.oz> 10/28/2008 8:01:21 AM

"Rj" <Rj[ at ]discussions.microsoft.com> wrote in message
news:1FFF9C6B-FC50-499F-8CA0-48DE9793BBA7[ at ]microsoft.com...
[Quoted Text]
> 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:
[ at ]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/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en


Re: scheduling deletion of specific files from folders
Rj 10/28/2008 10:33:01 AM
that worked great. Thankyou very much. I just modifed it a bit to get the
output to logfile.

[ at ]echo off
set logfile=C:\Backup.log
Echo %date% %time% >>%logfile%
set Limit=1
set Source=C:\Temp
set Dest=c:\Temp%random%
robocopy /NP /NJH /Mov /MinAge:%Limit% "%Source%" "%Dest%" *.bak >>%logfile%
rd /s /q "%Dest%" >>%logfile%

echo --------------------------------- >>%logfile%

"Pegasus (MVP)" wrote:

[Quoted Text]
>
> "Rj" <Rj[ at ]discussions.microsoft.com> wrote in message
> news:1FFF9C6B-FC50-499F-8CA0-48DE9793BBA7[ at ]microsoft.com...
> > 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:
> [ at ]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/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
>
>
>
Re: scheduling deletion of specific files from folders
"Pegasus \(MVP\)" <I.can[ at ]fly.com.oz> 10/28/2008 11:06:47 AM
Nice job! Thanks for the feedback.

"Rj" <Rj[ at ]discussions.microsoft.com> wrote in message
news:BD0CEDA8-03F5-42E4-BF4C-597B5E74AB76[ at ]microsoft.com...
[Quoted Text]
> that worked great. Thankyou very much. I just modifed it a bit to get the
> output to logfile.
>
> [ at ]echo off
> set logfile=C:\Backup.log
> Echo %date% %time% >>%logfile%
> set Limit=1
> set Source=C:\Temp
> set Dest=c:\Temp%random%
> robocopy /NP /NJH /Mov /MinAge:%Limit% "%Source%" "%Dest%" *.bak
> >>%logfile%
> rd /s /q "%Dest%" >>%logfile%
>
> echo --------------------------------- >>%logfile%
>
> "Pegasus (MVP)" wrote:
>
>>
>> "Rj" <Rj[ at ]discussions.microsoft.com> wrote in message
>> news:1FFF9C6B-FC50-499F-8CA0-48DE9793BBA7[ at ]microsoft.com...
>> > 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:
>> [ at ]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/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
>>
>>
>>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen