[VBScript] 自动删除2小时以前生成的文件

保存为deleteTempFiles.vbs,双击即可运行

dim folder, file, mFSO, subfolder
 
Set mFSO = CreateObject("Scripting.FileSystemObject")
set folder=mFSO.GetFolder("C:\Users\msautotestuser\AppData\Local\Temp")
'Delete files
dim df
For Each file In folder.files
    'df=DateDiff("h",file.DateCreated,Now)    'Create Date
    df=DateDiff("h",file.DateLastModified,Now)   'Modify Date
    If (df>2) Then    '2 hours ago
        'MsgBox folder.path & "\" & file.Name & vbTab & file.DateCreated
	'MsgBox folder.path & "\" & file.Name & vbTab & file.DateLastModified
	On Error Resume Next
        file.Delete()
    End If
Next
'Delete folders
set subfolder = Folder.subFolders
For Each file In subfolder
    'df=DateDiff("h",file.DateCreated,Now)    'Create Date
    df=DateDiff("h",file.DateLastModified,Now)    'Modify Date
    If (df>2) Then    '2 hours ago
	On Error Resume Next
        mFSO.deleteFolder(folder.path & "\" & file.Name)
    end if
next

  

posted on 2017-10-12 13:48  张缤分  阅读(366)  评论(0编辑  收藏  举报

导航