VBScript script implements the automatic acquisition of a file in the directory
1. Application scenario: multiple bulid of this version or historical version are usually retained on the development stream. How to script the latest build installation in the directory (there are many files with different names except build in the directory)? And there are usually version numbers that increase in turn in the naming of build, so how to make the script reusable every day?
2. Implementation idea: 1 > deal with the file name, define a constant file name, and replace the changed version number in the file name with *.
2 > given a known directory, get all the sub-files under the directory, and then split them by *, matching the file names of the sub-files and the names of the two parts of the split in turn.
3. The code is as follows:
'Description:fetch new build'author:Alan'Date:2014-10-31Function strFetchBuild (path,filename) Dim iLINAES FileNames = aGetAllFillname (path) If IsEmpty (FileNames) = false and IsArray (FileNames) Then' whether the filename format is right or not If Instr (filename, "*") > 0 Then 'according to * split filename splits=Split (filename) "*") For iTun0 To UBound (FileNames) flag=0'If each split block are matched, then return name For j = 0 To UBound (splits) If Instr (FileNames (I) Splits (j)) > 0 Then flag=flag+1 End If Next If flag= UBound (splits) + 1 Then strFetchBuild = path & "\" & FileNames (I) Else'If didn't match to the end of the loop Then exit function If i=UBound (FileNames) + 1 Then Log.Error ("The file:" & filename & "not found.") StrFetchBuild = "" Exit Function End If End If Next Else Log.Error ("The filename format" & "'& filename &" & "is not right.") StrFetchBuild = "" Exit Function End If Else Log.Error ("The path:" & path & "not exists.") StrFetchBuild = "" End If End Function