2010年8月5日木曜日

VBSのメモ

Option Explicit

'変数を用意
Dim objDir , objFile , objMFile , strDir , strMDir , temp(1) , curr(1) , count
'退避元フォルダを設定
strDir = "C:\Documents and Settings\Administrator\デスクトップ\vbs2\vbs\7.5\"
'退避先フォルダを設定
strMDir = "C:\Documents and Settings\Administrator\デスクトップ\vbs2\"

'ファイルシステムオブジェクトを作成
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objMFile = CreateObject("Scripting.FileSystemObject")
'対象フォルダの参照オブジェクトを作成
Set objDir = objFile.GetFolder(strDir)

count = 0
'メイン処理
For Each objFile In objDir.Files
'ファイルタイプで選別
IF objFile.Type = "ファイル" THEN
'対象フォルダ内のファイルを取得
IF count = 0 THEN
'初期操作
temp(0) = FormatDateTime(objFile.DateLastModified)
temp(1) = objFile.Name
ELSE
'初期操作完了済
curr(0) = FormatDateTime(objFile.DateLastModified)
curr(1) = objFile.Name
'ファイル更新日の比較
IF temp(0) <= curr(0) THEN
'Msgbox temp(1) & "を移動"
objMFile.MoveFile strDir & temp(1) , strMDir
temp(0) = curr(0)
temp(1) = curr(1)
ELSE
'Msgbox curr(1) & "を移動"
objMFile.MoveFile strDir & curr(1) , strMDir
END IF
END IF
count = count + 1
END IF
Next

'オブジェクトの破棄
set objFile = Nothing