1、 应用场景:通常在开发流上都会保留本版本或历史版本的多个bulid,若需要获取目录中(目录中除了build还有很多其他名称不一样的文件)最新的build安装该如何写脚本实现呢?而且通常build的命名中都会有依次增加的version号,该如何实现脚本可每日重复使用呢?
2、实现思路:1>处理文件名称,定义一个常量文件名,将文件名中的变化的version号用*代替;
2>给定已知的目录,获取给目录下所有的子文件,然后将按*分割,依次匹配子文件的文件名和被分割的这两部分名称。
3、代码如下:
'Description:fetch new build 'author:Alan 'Date:2014-10-31 Function strFetchBuild(path,filename) Dim i,j,FileNames,splits,flag 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 i=0 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 file name format" &"'" & filename & "'"&" is not right.") strFetchBuild = "" Exit Function End If Else Log.Error("The path:" & path & " not exists.") strFetchBuild = "" End If End Function
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/192865.html