下面的VBScript使用输入对话框中的输入生成两个文件。
下面我想将文件名(fileName
)添加到下面脚本中创建的JavaScript文件中的document.write('Confirm file"&filename&" completed');
。
但是当我这样做时,它返回引号中的变量名称,就像上面所写的那样而不是变量本身。我知道它与引号有关但我不知道该怎么做。任何帮助,将不胜感激。
fileName=InputBox("Enter a Name for the new SubRoutine: ","Enter Value","NewRoutine")
CreateFolder
CreateHTML
CreateJS
Sub CreateHTML
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile(fileName&"\"&fileName&".html")
objNewFile.WriteLine "<html>"
objNewFile.WriteLine "<head>"
objNewFile.WriteLine "<title>Created by Robot--MM</title>"
objNewFile.WriteLine "</head><body>"
objNewFile.WriteLine "<script type='text/javascript' src='"&fileName&".js'></script>"
objNewFile.WriteLine "<script>"&fileName&"()</script>"
objNewFile.WriteLine "</body>"
objNewFile.WriteLine "</html>"
objNewFile.Close
End Sub
Sub CreateJS
Set objFS = CreateObject("Scripting.FileSystemObject")
fileName2 = fileName & ".js"
Set objNewFilejs = objFS.CreateTextFile(fileName&"\"&fileName&".js")
objNewFilejs.WriteLine "var "&fileName&" = function() { window.alert('Hi,This is an alert from the file : "&fileName2&"');"
objNewFilejs.WriteLine "document.write('Confirmed file loaded.'); }"
objNewFilejs.Close
End Sub
Sub CreateFolder
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strFolder & "/"&fileName)
objShell.Run objFolder
Set Sh = Nothing
End Sub
答案 0 :(得分:0)
我已经简化了这个答案。我意识到我在错误的地方引用了引号。这是一些升级的解决方案。
fileName = InputBox("Please enter a name for your new files:", _"Create File")
US = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
Sub CreateHTML
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile(US &"\Desktop\"& fileName&".html")
objNewFile.WriteLine "<html>"
objNewFile.WriteLine"<link rel = 'stylesheet' href='"&fileName&".css'>"
objNewFile.WriteLine "<head>"
objNewFile.WriteLine "<title>Created by Robot--MM</title>"
objNewFile.WriteLine "</head><body>"
objNewFile.WriteLine "<script type='text/javascript' src='"&fileName&".js'></script>"
objNewFile.WriteLine "<script> "&fileName&"()""</script>"
objNewFile.WriteLine "</body>"
objNewFile.WriteLine "</html>"
objNewFile.Close
End Sub
CreateHTML
Sub CreateJS
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFilejs = objFS.CreateTextFile(US &"\Desktop\"& fileName&".js")
objNewFilejs.WriteLine "window.alert('Hi,This is an alert from the file ');"
objNewFilejs.WriteLine "document.write('Document loaded')"
objNewFilejs.Close
End Sub
CreateJS
Sub CreateCSS
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFileCSS = objFS.CreateTextFile(US &"\Desktop\"& fileName&".css")
objNewFilecss.WriteLine "body {text-align:center;font-family:'Zapfino',serif;}"
objNewFilecss.Close
End Sub
CreateCSS