#freeze
* リファレンス [#a80d098c]
-[[VBScript ランゲージ リファレンス:http://tryasp.winscom.co.jp/document/vbscript/vbstoc.htm]]
-[[VBScript Guide:http://winofsql.jp/enum/vbsguide/frame.htm]]

* 各処理 [#bdf08310]
** 文字列処理 [#pd88af82]
-[[文字列のトークン切り出し:http://www.codeproject.com/vbscript/tokenize.asp?df=100&forumid=676&exp=0&select=1056235]]

*** パスからファイルの拡張子を除いた文字列を返す関数 [#n88cb6ce]
 Function RemoveExtension(sPath)
     Dim sExt, sFileName
 	
     Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
     sFileName = objFSO.GetFileName(sPath)
     sExt = objFSO.GetExtensionName(sPath)
 	
     RemoveExtension = Replace(sPath, sFileName, Replace(sFileName, "."&sExt, ""))
 End Function

** プログラム実行 [#x1af0ffb]
-[[プログラムの実行 (Exec):http://www.atmarkit.co.jp/fwin2k/operation/wsh05/wsh05_03.html]]
-[[データ入出力 (StdIn, StdOut, StdErr):http://www.atmarkit.co.jp/fwin2k/operation/wsh03/wsh03_03.html]]

*** 引数で渡されたコマンドを実行し、終了コードを返す関数 [#y675e1c5]
 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://www.atmarkit.co.jp/fwin2k/operation/wsh04/wsh04_03.html]]

*** 入力されたパラメータをそのまま渡したい場合 [#k64a1685]
入力されたパラメータをそのまま別のプログラムのパラメーターとして渡したい場合、WScript.Arguments.Item(n) とかで取得した値をそのまま使うと、"(ダブルコーテーション)が取れたものを渡してしまうため、不都合が生じる。~
そこで下記のようにして、値を全て " で囲んだ文字列を生成して渡す。

 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 & ":" & """" & objArgs.Named.Item(name) & """"
     End If
 Next

** XML処理 [#kf29433e]
-[[XML Developer Center:http://www.microsoft.com/japan/msdn/xml/default.asp]]

-[[VBScriptでXMLプログラミング:http://www.atmarkit.co.jp/fxml/indexes/index_all.html#vbscr]]
-[[WSHによるDOMの利用について:http://ash.jp/xml/wsh/index.htm]]
-[[DOMを利用してXMLデータへアクセス:http://www.kanaya440.com/contents/tips/vbs/003.html]]

-[[Working with XML Document Parts:http://doc.ddart.net/xmlsdk/htm/dom_concepts_1u9f.htm]]

*** 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("male")
 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("address")
 Set person_addressElementText = xmlDoc.createTextNode("東京都世田谷区")
 person_addressElement.AppendChild(person_addressElementText)
 
 '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/tips0063.html]]
-[[ブラウザの閉じるボタンが押されたイベントを拾って処理:http://forums.microsoft.com/MSDN-JA/ShowPost.aspx?PostID=559017&SiteID=7]]

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS