'#####################################################################
'未テスト
'
'
'#####################################################################
Option Explicit
'実運用時はコメントアウトのこと
On Error Resume Next
Dim WshNetwork
Dim strDate, strBackup, strPath, strOldestFile
Dim strYear, strMonth, strDay, strTargetDate
Dim index, FileList
Dim objShell, objFile, objWMIService
Dim dtmDate
Set objShell = Wscript.CreateObject("WScript.Shell")
Set WshNetwork = Wscript.CreateObject("WScript.Network")
'Z:ドライブが使用されていれば切断
RemoveNetworkDrive()
'ネットワークドライブの接続
WshNetwork.MapNetworkDrive "Z:", "file://127.0.0.1/work", False
'バックアップ実行コマンドの作成
strBackup = "C:\WINDOWS\system32\ntbackup.exe backup ""@C:\Documents and Settings\rikei\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\FullBackup.bks"" /a /d ""ウィークリーバックアップセット"" /v:no /r:no /rs:no /hc:off /m normal /j ""FullBackup"" /l:s /f ""Z:\"""
'本日の日付でファイル名を作成
dtmDate = Date
GetDate (dtmDate)
'最後の"を取り除き、日付_full.bkfというファイル名を指定
index = Len(strBackup) - 1
strPath = Left(strBackup, index) & strTargetDate & "_full.bkf"
'コマンドの実行
objShell.Run (strPath)
'???????????????????????
'古いファイルの削除
'???????????????????????
'本日から何日以前のファイルを対象にするか指定
dtmDate = Date - 13
'指定条件でファイル名を生成
GetDate (dtmDate)
'
Set objWMIService = GetObject("winmgmts:\\" & "127.0.0.1" & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\work\Upload'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
strDate = Left(objFile.LastModified,
Wscript.echo strDate
If strDate < strTargetDate Then
'If objFile.Extension = “_full.bkf” Then
'objFile.Delete
'End If
End If
Next
'ネットワークドライブの切断
RemoveNetworkDrive()
'終了処理
Set WshNetwork = Nothing
Set objShell = Nothing
'ここまで
'???????????????????????
'ネットワークドライブの切断
Private Function RemoveNetworkDrive()
On Error Resume Next
WshNetwork.RemoveNetworkDrive "Z:", False, True
End Function
'???????????????????????
'ファイル名、Date整形
Function GetDate(dtmDate)
strDay = Day(dtmDate)
If Len(strDay) < 2 Then
strDay = "0″ & strDay"
End If
strMonth = Month(dtmDate)
If Len(strMonth) < 2 Then
strMonth = "0″ & strMonth"
End If
strYear = Year(dtmDate)
strTargetDate = strYear & strMonth & strDay
End Function
'???????????????????????