好的,我正在打架,这里应该是简单的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")
答案 0 :(得分:2)
....
For Each f1 in objFolder.SubFolders
GetFolderName = GetFolderName(f1.Path,Computer)
If GetFolderName <> vbEmpty Then Exit For
Next
....
答案 1 :(得分:1)
与 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")