Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBScript递归函数问题返回值_Vbscript - Fatal编程技术网

VBScript递归函数问题返回值

VBScript递归函数问题返回值,vbscript,Vbscript,我正在战斗什么应该是简单的VBScript函数在这里。我的脚本的目标是获取2个输入值并找到匹配的子文件夹。然后我希望函数返回该文件夹的路径。下面是我所拥有的,但是我很难让它返回值。它似乎没有退出函数并返回值 这是我到目前为止所拥有的 Function GetFolderName(folderspec,Computer) WScript.Echo "checking: " & folderspec Set fso = CreateObject("Scripting.File

我正在战斗什么应该是简单的VBScript函数在这里。我的脚本的目标是获取2个输入值并找到匹配的子文件夹。然后我希望函数返回该文件夹的路径。下面是我所拥有的,但是我很难让它返回值。它似乎没有退出函数并返回值

这是我到目前为止所拥有的

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")
。。。。
对于objFolder.SubFolders中的每个f1
GetFolderName=GetFolderName(f1.路径,计算机)
如果GetFolderName vbEmpty,则为退出
下一个
....

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")
函数GetFolderName(folderspec,计算机) “WScript.Echo”检查:“&folderspec” 设置fso=CreateObject(“Scripting.FileSystemObject”) 设置objFolder=fso.GetFolder(folderspec) 如果UCase(objFolder.Name)=UCase(计算机),则 GetFolderName=folderspec 退出功能 如果结束 设置arrSubfolders=objFolder.SubFolders 对于objFolder.SubFolders中的每个f1 GetFolderName=GetFolderName(f1.路径,计算机) 如果GetFolderName vbEmpty,则为退出 下一个 端函数 '********************************************************************************************** MsgBox GetFolderName(“C:\Test”、“Trial3”)
正是我所需要的。我是如此接近!感谢您使它成为一个简单的复制/粘贴!
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")