Skip to content

Instantly share code, notes, and snippets.

@motoraku
Created December 25, 2015 13:08
Show Gist options
  • Select an option

  • Save motoraku/9bf3b6eaebcf924ce983 to your computer and use it in GitHub Desktop.

Select an option

Save motoraku/9bf3b6eaebcf924ce983 to your computer and use it in GitHub Desktop.
テキストファイルをバイナリファイルへ変換 : Convert text file to binary file
WScript.Quit((function() {
// 入力ファイル名、出力ファイル名を受け取る
if(WScript.Arguments.length < 1) {
//WScript.Echo("args : (text file path)");
return 1;
}
// ファイル読み込み
var ins = WScript.CreateObject('ADODB.Stream');
ins.Open();
ins.Charset = "iso-8859-1";
ins.Type = 2; // Text
ins.LoadFromFile(WScript.Arguments.item(0))
// バイト配列操作用オブジェクト
var binMan = WScript.CreateObject('Microsoft.XMLDOM').createElement('tmp');
binMan.dataType = "bin.base64";
binMan.text = ins.ReadText()
ins.Close()
ins = null;
// ファイル書き込み
var outs = WScript.CreateObject('ADODB.Stream');
outs.Open();
outs.Charset = "iso-8859-1";
outs.Type = 1; // Binary
outs.Write(binMan.nodeTypedValue);
binMan = null;
outs.SaveToFile(WScript.Arguments.item(0)+".bny", 2);
outs.Close();
outs = null;
return 0;
})());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment