Find latest modified files in specified folder

上一篇 / 下一篇  2009-06-12 13:57:38 / 个人分类:VBScript & QTP

'------------------------------------
'Purpose: Find the latest update file according modify time
'Function Name: GoThroughFolder(FolderPath, ModifyTime)
'               FolderPath----Folder path
'               ModifyTime----Modify time
'Author: Jay Yang
'Data: 2009-06-12
'------------------------------------
Function GoThroughFolder(FolderPath, ModifyTime)
    Dim fso, f, f1, fc, s, f2,fc2
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(FolderPath)
    Set fc = f.Files
    Set fc2 = f.SubFolders
    For Each f2 in fc2
        'msgbox f2.name
        Call GoThroughFolder(FolderPath&"\"&f2.name, ModifyTime)
    Next
    For Each f1 in fc
        'Just compare specified type file
        If f1.Type="SilkTest Include File" or f1.Type="SilkTest Script. File" Then
           Tday = DiffADate("d",f1.DateLastModified, ModifyTime)
           If Tday > 0 Then
               Call OpenTextFileTest(FolderPath&"\"&f1.name&"      "&f1.DateLastModified)
           ElseIf Tday = 0 Then
               Thour = DiffADate("h",f1.DateLastModified, ModifyTime)
               If Thour > 0 Then
                   Call OpenTextFileTest(FolderPath&"\"&f1.name&"      "&f1.DateLastModified)
               ElseIf Thour = 0 Then
                         TMin = DiffADate("n",f1.DateLastModified, ModifyTime)
                         If TMin > 0 Then
                              Call OpenTextFileTest(FolderPath&"\"&f1.name&"      "&f1.DateLastModified)
                         End If
               End If
           End If
        End If
    Next
End Function

Function DiffADate(TFormat, Search_lagerthan_Date, File_Modify_Data)
  DiffADate = DateDiff(TFormat, File_Modify_Data, Search_lagerthan_Date)
End Function

Function CreateAfile
  Dim fso, MyFile
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set MyFile = fso.CreateTextFile(".\Update_File_List.txt", True)
  MyFile.WriteLine("Following is update file list:")
  MyFile.WriteLine("-------------------------------------------------------------------------------")
  MyFile.Close
End Function
 
Function OpenTextFileTest(Content)
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(".\Update_File_List.txt", ForAppending, True)
  f.Writeline Content
  f.Close
End Function
 
CreateAfile
Call GoThroughFolder("C:\WorkArea\fear", "2009-6-9 10:00:00")
msgbox "Done!"

TAG:

 

评分:0

我来说两句

日历

« 2024-04-17  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 13769
  • 日志数: 28
  • 书签数: 1
  • 建立时间: 2009-04-02
  • 更新时间: 2010-06-09

RSS订阅

Open Toolbar