Vbscript &引用;“未找到路径”;使用inputBox变量时
我正在构建一个脚本,该脚本使用用户的输入为源文件夹创建路径。如果我使用完整路径(已注释掉的路径),这是可行的。否则我会得到“未找到路径”。有人能把我引向正确的方向吗Vbscript &引用;“未找到路径”;使用inputBox变量时,vbscript,Vbscript,我正在构建一个脚本,该脚本使用用户的输入为源文件夹创建路径。如果我使用完整路径(已注释掉的路径),这是可行的。否则我会得到“未找到路径”。有人能把我引向正确的方向吗 Set objFSO = CreateObject("Scripting.FileSystemObject") Dim sFolder : sFolder = "S:\" & newState & "\" & "Section_" & newSection & "\Images-trace
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim sFolder : sFolder = "S:\" & newState & "\" & "Section_" & newSection & "\Images-tracetest"
'Dim sFolder : sFolder = "S:\SOCAL\Section_31\Images-tracetest"
Dim newState, newSection, newArea, sFile
Call GetNewInputs()
REM======================New Inputs===============================
Sub GetNewInputs()
newState = UCase(InputBox("INPUT STATE or REGION:", _
"INPUT STATE", "SOCAL"))
newSection = ("Section_" & InputBox("INPUT SECTION NUMBER:", _
"INPUT SECTION", "31"))
End Sub
For Each sFile In objFSO.GetFolder(sFolder).Files
uSplit = split(file,"_")
newArea = uSplit(ubound(uSplit) - 1)
If InStr(sFile.Name, "CC") > 0 Then
WScript.Echo "We found a CC file! File is" & (sFile.name)
Else
End If
Next
为什么它不会抛出一个错误。在获取用户输入之前,您正在创建变量sFolder。因此,即使用户输入它们,它们也不会被使用。Dim语句或变量初始化发生在任何子语句或函数外部初始化时的最开始。你必须这样做
Set objFSO = CreateObject("Scripting.FileSystemObject")
**public sFolder**
'Dim sFolder : sFolder = "S:\SOCAL\Section_31\Images-tracetest"
Dim newState, newSection, newArea, sFile
Call GetNewInputs()
REM======================New Inputs===============================
Sub GetNewInputs()
newState = UCase(InputBox("INPUT STATE or REGION:", _
"INPUT STATE", "SOCAL"))
newSection = ("Section_" & InputBox("INPUT SECTION NUMBER:", _
"INPUT SECTION", "31"))
**sFolder = "S:\" & newState & "\" & "Section_" & newSection & "\Images-tracetest"**
End Sub
For Each sFile In objFSO.GetFolder(sFolder).Files
uSplit = split(file,"_")
newArea = uSplit(ubound(uSplit) - 1)
If InStr(sFile.Name, "CC") > 0 Then
WScript.Echo "We found a CC file! File is" & (sFile.name)
Else
End If
Next
此外,您还添加了两次“Section_”:
s文件夹的diagnostic.Echo
是个好主意。您可能希望添加:在开始时添加选项Explicit
对于停止此类错误非常重要
sFolder = "S:\" & newState & "\" & "Section_" & newSection & "\Images-tracetest"
newSection = ("Section_" & InputBox("INPUT SECTION NUMBER:", _
"INPUT SECTION", "31"))