VBScript 递归函数问题返回值

VBScript recursive function issue returning value

我在这里打架应该是简单的 VBScript 函数。我的脚本的目标是获取 2 个输入值并找到匹配的子文件夹。然后我希望函数 return 该文件夹的路径。以下是我所拥有的,但我无法将其设为 return 值。它似乎没有退出函数并 returning 值。

这是我目前的情况。

Function GetFolderName(folderspec,Computer)
    WScript.Echo "checking: " & folderspec
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFolder = fso.GetFolder(folderspec)
    If UCase(objFolder.Name) = UCase(Computer) Then
        GetFolderName = folderspec
        Exit Function
    End If
    Set arrSubfolders = objFolder.SubFolders
    For Each f1 in arrSubfolders
            folderspec = GetFolderName(f1.Path,Computer)
    Next
End Function

strFolder = GetFolderName("C:\Test","Trial3")
....
For Each f1 in objFolder.SubFolders
    GetFolderName = GetFolderName(f1.Path,Computer)
    If GetFolderName <> vbEmpty Then Exit For
Next
....

喜欢MC ND你可以这样试试:

Function GetFolderName(folderspec,Computer)
'WScript.Echo "checking: " & folderspec
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFolder = fso.GetFolder(folderspec)
    If UCase(objFolder.Name) = UCase(Computer) Then
        GetFolderName = folderspec
        Exit Function
    End If
    Set arrSubfolders = objFolder.SubFolders
    For Each f1 in objFolder.SubFolders
        GetFolderName = GetFolderName(f1.Path,Computer)
        If GetFolderName <> vbEmpty Then Exit For
    Next
End Function
'**********************************************************************************************
MsgBox GetFolderName("C:\Test","Trial3")