将两个值添加到 VBScript 数组并比较它们是否彼此相等

问题描述

在这里想要实现的是获取 objLibrarySourceobjLibraryDest 的两个文件夹大小值,并使用 if 语句来比较两个文件大小,如果它们彼此相等,则将其传送到文本文件-> objFile.WriteLine "Match"。但我的问题是我只得到 arrayList(0) 而不是 arrayList(1)

的值

代码

myArray = Array(objLibrarySource,objLibraryDest)
For Each item In myArray
    Set objFolder = objFSO.GetFolder(item)
    totalSize = objFolder.Size / 1073741824

    arrayList = Array()
    arrayList = AddItem(arrayList,totalSize)
    arrayList = Split(Join(arrayList) & " ")

    objFile.WriteLine objFolder & " File Size: " & Round(totalSize,2) & " GB"

    If (arrayList(0) = arrayList(1)) Then
        objFile.WriteLine "Match"
    End If
Next
    objFile.WriteLine arrayList(0) & vbCrLf
    objFile.WriteLine arrayList(1)

Function AddItem(arr,val)
    ReDim Preserve arr(UBound(arr) + 1)
    arr(UBound(arr)) = val
    AddItem = arr
End Function

输出

D:\LIBRARY_TEST File Size: 7.01 GB
D:\seed_backup\LIBRARY File Size: 7.01 GB
7.01436613406986

解决方法

我不得不重构我的代码以

Dim libsizesrc,libsizedst,libsizesrcSize,libsizedstSize
Set libsizesrc = objFSO.GetFolder(objLibrarySource)
Set libsizedst = objFSO.GetFolder(objLibraryDest)
libsizesrcSize = libsizesrc.Size / 1073741824
libsizedstSize = libsizedst.Size  / 1073741824
objFile.WriteLine libsizesrc & " File Size: " & Round(libsizesrcSize,2) & " GB"
objFile.WriteLine libsizedst & " File Size: " & Round(libsizedstSize,2) & " GB"

'Source & Dest SMPDevices Sizes
Dim SMPsizesrc,SMPsizedst,SMPsizesrcSize,SMPsizedstSize
Set SMPsizesrc = objFSO.GetFolder(objSMPDriversSource)
Set SMPsizedst = objFSO.GetFolder(objSMPDriversDest)
SMPsizesrcSize = SMPsizesrc.Size / 1073741824
SMPsizedstSize = SMPsizedst.Size  / 1073741824
objFile.WriteLine SMPsizesrc & " File Size: " & Round(SMPsizesrcSize,2) & " GB"
objFile.WriteLine SMPsizedst & " File Size: " & Round(SMPsizedstSize,2) & " GB"

'Library & Source Folder Size Verification
If (libsizesrcSize = libsizedstSize) Then
    objFile.Write "Library Folder FileSize Match!" & vbCrLf
End If

If (SMPsizesrcSize = SMPsizedstSize) Then
    objFile.Write "SMPDrivers Folders FileSize Match!"
End If

它可以根据需要工作!