SSブログ

タスクスケジューラと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)


nice!(0)  コメント(0)  トラックバック(0) 

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

-|Windows Server 2008 .. ブログトップ

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。