码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-12 14:34:00      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:cal   monk   logs   rom   div   erro   删除   log   object   

copy from http://www.cnblogs.com/MasterMonkInTemple/p/7655734.html

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

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

标签:cal   monk   logs   rom   div   erro   删除   log   object   

原文地址:http://www.cnblogs.com/kill0001000/p/7655898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!