游戏数据更新检查

类型|存放数据的文件夹(相对路径)

类型1|gameData\95vs\origin
类型2|gameData\loude\origin
类型3|gameData\trid\origin
类型4|gameData\xway\origin

读取上面的数据,遍历每个类型对应的文件夹,检查最近更新的时间。并显示

Dim FSO, Folder, listFilePath, currentpath
Set FSO = CreateObject("Scripting.FileSystemObject")
currentpath = FSO.GetFile(Wscript.ScriptFullName).ParentFolder.Path & "\" '当前路径
listFilePath = currentpath & "gameDataType.txt" '从此文件读要处理的目录,每行一条数据,格式为:类型|文件路径

'--------------读取数据,返回二维数组-------------------
function get_list(FilePath) 
	On Error Resume Next 
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile(FilePath , 1)
	
	Do Until objTextFile.AtEndOfStream
		strNextLine = objTextFile.Readline
		mylist = mylist & strNextLine & "$"
	Loop
	
	Dim list ,arrLen
	list = Split(mylist, "$") '
	arrLen = ubound(list) - 1
	
	'声明动态数组
	ReDim Preserve gameDateTypeArray(arrLen)

	'遍历每条数据,切成数组
	For i = 0 To arrLen
		gameDateTypeArray(i) = Split(list(i), "|")
	Next
	
	get_list = gameDateTypeArray
end function 

' -------------- 遍历文件夹,返回最新文件的创建时间 --------------
function checkdate(LogPath)
	Dim myDate, fn '定义两个变量用于bai在遍du历时记录最新的创建时间和文件zhi名dao
	myDate = "1990-01-01 00:00:00" '设定一个时间初始值用于后续比较
	If FSO.FolderExists(LogPath) Then 
	
	    Set Folder = FSO.GetFolder(LogPath)
	    For Each File In Folder.Files
			' 以秒为单位。文件创建时间 - myDate 大于0,说明文件时间比较新
            If DateDiff("s", myDate, File.DateCreated) > 0 Then
                myDate = File.DateCreated
            End If
	    Next
	    Set Folder = Nothing
	    
	End If

	checkdate = myDate
end Function


'-------------------------- 游戏数据推送时间检查,拼接显示结果 ---------------------
Function checkPathList(gameDateTypeArray)
	Dim pathList, arrLen, tempArr
	arrLen = UBound(gameDateTypeArray) ' 获取数组长度
	ReDim Preserve resultArr(arrLen) '创建动态数组,用来装返回结果
	
	For i = 0 To arrLen 
		tempArr = gameDateTypeArray(i)
		resultArr(i) =  tempArr(0) & " :【" & checkdate(currentpath & tempArr(1)) & "】 :" & tempArr(1)
	Next
	
	checkPathList = Join(resultArr, Chr(13)) '数组转字符串
End Function

msgbox checkPathList(get_list(listFilePath)), ,"游戏数据更新检查  jerryjin 20200623" 

你可能感兴趣的:(VBS,vbs,vbscript)