'------------------------------------
'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!"