VBScript
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
* リファレンス [#a80d098c]
-[[VBScript ランゲージ リファレンス:http://tryasp.winscom...
-[[VBScript Guide:http://winofsql.jp/enum/vbsguide/frame....
* 各処理 [#bdf08310]
** 文字列処理 [#pd88af82]
-[[文字列のトークン切り出し:http://www.codeproject.com/vb...
*** パスからファイルの拡張子を除いた文字列を返す関数 [#n8...
Function RemoveExtension(sPath)
Dim sExt, sFileName
Set objFSO = WScript.CreateObject("Scripting.FileSys...
sFileName = objFSO.GetFileName(sPath)
sExt = objFSO.GetExtensionName(sPath)
RemoveExtension = Replace(sPath, sFileName, Replace(...
End Function
** プログラム実行 [#x1af0ffb]
-[[プログラムの実行 (Exec):http://www.atmarkit.co.jp/fwin...
-[[データ入出力 (StdIn, StdOut, StdErr):http://www.atmark...
*** 引数で渡されたコマンドを実行し、終了コードを返す関数 ...
Const DEBUG_MODE = true
'コマンド実行
Function ExecCommand(sCommand)
Set objShell = WScript.CreateObject("WScript.Shell")
If DEBUG_MODE Then
WScript.Echo sCommand
'イベントログ:アプリケーションに書き出し
objShell.LogEvent INFORMATION, "transcode: " & sCommand
End If
Set objExec = objShell.Exec(sCommand)
'実行終了まで待つ
Do While objExec.Status = 0
WScript.Sleep 100
Loop
sStdOut = ""
Do Until objExec.StdOut.AtEndOfStream
sStdOut = objExec.StdOut.ReadLine
Loop
WScript.StdOut.Write sStdOut
If objExec.ExitCode <> 0 Then
sStdErr = ""
Do Until objExec.StdErr.AtEndOfStream
sStdErr = objExec.StdErr.ReadLine
Loop
WScript.StdErr.Write sStdErr
End If
'WScript.Quit(objExec.ExitCode)
ExecCommand = objExec.ExitCode
End Function
** パラメーターの取得 [#ob09aae9]
-[[名前付きパラメータ/名前なしパラメータの取扱:http://ww...
*** 入力されたパラメータをそのまま渡したい場合 [#k64a1685]
入力されたパラメータをそのまま別のプログラムのパラメータ...
そこで下記のようにして、値を全て " で囲んだ文字列を生成し...
objArgs = WScript.Arguments
sArgs = ""
'名前なしパラメータの処理
For Each item In objArgs.Unnamed
sArgs = sArgs & " " & """" & item & """"
Next
'名前つきパラメータの処理
For Each name In objArgs.Named
sVal = objArgs.Named.Item(name)
If sVal="" Then
sArgs = sArgs & " /" & name
Else
sArgs = sArgs & " /" & name & ":" & """" & objAr...
End If
Next
** XML処理 [#kf29433e]
-[[XML Developer Center:http://www.microsoft.com/japan/ms...
-[[VBScriptでXMLプログラミング:http://www.atmarkit.co.jp/...
-[[WSHによるDOMの利用について:http://ash.jp/xml/wsh/index...
-[[DOMを利用してXMLデータへアクセス:http://www.kanaya440....
-[[Working with XML Document Parts:http://doc.ddart.net/x...
*** XMLを生成してファイルに書き出す例 [#r79459d4]
' 以下のXMLをファイル(test.xml)に書き出す
'
' <persons>
' <person sex="male">
' <name>山田太郎</name>
' <address>東京都世田谷区</address>
' </person>
' </persons>
'XML文書の生成
Set xmlDoc = WScript.CreateObject("MSXML2.DOMDocument")
'<persons>
Set rootElement = xmlDoc.createElement("persons")
'<person>
Set personElement = xmlDoc.createElement("person")
Set person_sexAttribute = xmlDoc.createAttribute("sex")
Set person_sexAttributeText = xmlDoc.createTextNode("mal...
person_sexAttribute.appendChild(person_sexAttributeText)
personElement.setAttributeNode(person_sexAttribute)
'<person>/<name>
Set person_nameElement = xmlDoc.createElement("name")
Set person_nameElementText = xmlDoc.createTextNode("山田...
person_nameElement.AppendChild(person_nameElementText)
'<person>/<address>
Set person_addressElement = xmlDoc.createElement("addres...
Set person_addressElementText = xmlDoc.createTextNode("...
person_addressElement.AppendChild(person_addressElementT...
'XML文書の組み立て
xmlDoc.appendChild(rootElement)
rootElement.appendChild(personElement)
personElement.appendChild(person_nameElement)
personElement.appendChild(person_addressElement)
'XML文書の書き出し
xmlDoc.save("test.xml")
* Tips [#od292763]
-[[VBScript Tips:http://www.whitire.com/vbs/index.html]]
-[[一時ファイル名の作成:http://www.whitire.com/vbs/tips00...
-[[ブラウザの閉じるボタンが押されたイベントを拾って処理:h...
終了行:
* リファレンス [#a80d098c]
-[[VBScript ランゲージ リファレンス:http://tryasp.winscom...
-[[VBScript Guide:http://winofsql.jp/enum/vbsguide/frame....
* 各処理 [#bdf08310]
** 文字列処理 [#pd88af82]
-[[文字列のトークン切り出し:http://www.codeproject.com/vb...
*** パスからファイルの拡張子を除いた文字列を返す関数 [#n8...
Function RemoveExtension(sPath)
Dim sExt, sFileName
Set objFSO = WScript.CreateObject("Scripting.FileSys...
sFileName = objFSO.GetFileName(sPath)
sExt = objFSO.GetExtensionName(sPath)
RemoveExtension = Replace(sPath, sFileName, Replace(...
End Function
** プログラム実行 [#x1af0ffb]
-[[プログラムの実行 (Exec):http://www.atmarkit.co.jp/fwin...
-[[データ入出力 (StdIn, StdOut, StdErr):http://www.atmark...
*** 引数で渡されたコマンドを実行し、終了コードを返す関数 ...
Const DEBUG_MODE = true
'コマンド実行
Function ExecCommand(sCommand)
Set objShell = WScript.CreateObject("WScript.Shell")
If DEBUG_MODE Then
WScript.Echo sCommand
'イベントログ:アプリケーションに書き出し
objShell.LogEvent INFORMATION, "transcode: " & sCommand
End If
Set objExec = objShell.Exec(sCommand)
'実行終了まで待つ
Do While objExec.Status = 0
WScript.Sleep 100
Loop
sStdOut = ""
Do Until objExec.StdOut.AtEndOfStream
sStdOut = objExec.StdOut.ReadLine
Loop
WScript.StdOut.Write sStdOut
If objExec.ExitCode <> 0 Then
sStdErr = ""
Do Until objExec.StdErr.AtEndOfStream
sStdErr = objExec.StdErr.ReadLine
Loop
WScript.StdErr.Write sStdErr
End If
'WScript.Quit(objExec.ExitCode)
ExecCommand = objExec.ExitCode
End Function
** パラメーターの取得 [#ob09aae9]
-[[名前付きパラメータ/名前なしパラメータの取扱:http://ww...
*** 入力されたパラメータをそのまま渡したい場合 [#k64a1685]
入力されたパラメータをそのまま別のプログラムのパラメータ...
そこで下記のようにして、値を全て " で囲んだ文字列を生成し...
objArgs = WScript.Arguments
sArgs = ""
'名前なしパラメータの処理
For Each item In objArgs.Unnamed
sArgs = sArgs & " " & """" & item & """"
Next
'名前つきパラメータの処理
For Each name In objArgs.Named
sVal = objArgs.Named.Item(name)
If sVal="" Then
sArgs = sArgs & " /" & name
Else
sArgs = sArgs & " /" & name & ":" & """" & objAr...
End If
Next
** XML処理 [#kf29433e]
-[[XML Developer Center:http://www.microsoft.com/japan/ms...
-[[VBScriptでXMLプログラミング:http://www.atmarkit.co.jp/...
-[[WSHによるDOMの利用について:http://ash.jp/xml/wsh/index...
-[[DOMを利用してXMLデータへアクセス:http://www.kanaya440....
-[[Working with XML Document Parts:http://doc.ddart.net/x...
*** XMLを生成してファイルに書き出す例 [#r79459d4]
' 以下のXMLをファイル(test.xml)に書き出す
'
' <persons>
' <person sex="male">
' <name>山田太郎</name>
' <address>東京都世田谷区</address>
' </person>
' </persons>
'XML文書の生成
Set xmlDoc = WScript.CreateObject("MSXML2.DOMDocument")
'<persons>
Set rootElement = xmlDoc.createElement("persons")
'<person>
Set personElement = xmlDoc.createElement("person")
Set person_sexAttribute = xmlDoc.createAttribute("sex")
Set person_sexAttributeText = xmlDoc.createTextNode("mal...
person_sexAttribute.appendChild(person_sexAttributeText)
personElement.setAttributeNode(person_sexAttribute)
'<person>/<name>
Set person_nameElement = xmlDoc.createElement("name")
Set person_nameElementText = xmlDoc.createTextNode("山田...
person_nameElement.AppendChild(person_nameElementText)
'<person>/<address>
Set person_addressElement = xmlDoc.createElement("addres...
Set person_addressElementText = xmlDoc.createTextNode("...
person_addressElement.AppendChild(person_addressElementT...
'XML文書の組み立て
xmlDoc.appendChild(rootElement)
rootElement.appendChild(personElement)
personElement.appendChild(person_nameElement)
personElement.appendChild(person_addressElement)
'XML文書の書き出し
xmlDoc.save("test.xml")
* Tips [#od292763]
-[[VBScript Tips:http://www.whitire.com/vbs/index.html]]
-[[一時ファイル名の作成:http://www.whitire.com/vbs/tips00...
-[[ブラウザの閉じるボタンが押されたイベントを拾って処理:h...
ページ名: