我正在构建一个脚本,该脚本使用用户的输入来创建源文件夹的路径。如果我使用完整路径(已注释掉的路径),这是有效的。否则我会找到" Path Not Found"。有人能引导我朝着正确的方向前进吗?
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
答案 0 :(得分:0)
为什么不会抛出错误。在获取用户输入之前,您正在创建变量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
答案 1 :(得分:0)
此外,您添加" Section _"两次:
sFolder = "S:\" & newState & "\" & "Section_" & newSection & "\Images-tracetest"
newSection = ("Section_" & InputBox("INPUT SECTION NUMBER:", _
"INPUT SECTION", "31"))
诊断。sFolder
的回声本来是个好主意。