タスクスケジューラとWSH(VBScript)で一定時間以前のファイルを削除する
前日の夜間バッチで作成されるゴミファイルを削除する目的で、
作成時間が一定時間以前のファイルが存在していた場合、そのファイルを削除する。
Windowsのタスクスケジューラで毎日定時に実行させる。
スクリプトを掲載、タスクスケジューラの設定は割愛。
---------------------------------------------
Option Explicit
Dim objFso
Dim objFile
Dim strNow
Dim strFnm
strNow = Now()
strFnm = "C:\TargetFolder1\TargetFolder2\TargetFile.ext"
Set objFso = CreateObject("Scripting.FileSystemObject")
'presence check of file
If objFso.FileExists(strFnm) Then
Set objFile = objFso.GetFile(strFnm)
'comparison of file created time
If objFile.DateCreated < DateAdd("h",-15,strNow) Then
'for debug
'WScript.Echo "Created=" & objFile.DateCreated & " < SetTime=" & DateAdd("h",-15,strNow)
objFso.DeleteFile strFnm, True
End If
End If
Set objFso = Nothing
Set objFile = Nothing
---------------------------------------------
(Windows XP, Windows 2008 R2x64, WSH, VBscript)
2013-10-15 14:43
nice!(0)
コメント(0)
トラックバック(0)
コメント 0