SoftwareEngineering

情報が集まってきたら整理する。 それまではこのページに書いていく。

実行中のスクリプトが存在するパスを取得する。

var _DirectoryPath = WScript.ScriptFullName.replace(/[\\\/]([^\\\/]+)$/, '');

XMLの操作

Microsoft.XMLDOMを使用して、XMLを読み込む

Active Directory

Microsoft Office

入力ダイアログボックス

/// ---------------------------------------------------------------------------
/// <summary>入力ダイアログボックス</summary>
/// ---------------------------------------------------------------------------
function InputBox() {
    this.script = new ActiveXObject('ScriptControl');
    this.script.Language = 'VBScript';
    this.script.AddCode('Function IB(prompt, ditle, default)\n IB = InputBox(prompt, ditle, default)\n End Function');
}


/// ---------------------------------------------------------------------------
/// <summary>入力ダイアログボックスを表示する</summary>
/// <param name="APrompt">ダイアログ ボックス内にメッセージとして表示する文字列</param>
/// <param name="ATitle">ダイアログ ボックスのタイトル バーに表示する文字列 </param>
/// <param name="ADefault">テキスト ボックスに既定値として表示する文字列</param>
/// ---------------------------------------------------------------------------
InputBox.prototype.prompt = function(APrompt, ATitle, ADefault) {
    return this.script.Run('IB', APrompt, ATitle, ADefault);
} 


var _InputBox = new InputBox();
var _InputText = _InputBox.prompt('APrompt', 'ATitle', 'ADefault');

WScript.Echo(_InputText);

配列

二次元配列の縦と横を入れ替える

/// ---------------------------------------------------------------------------
/// <summary>標準出力画面に値を表示する</summary>
/// ---------------------------------------------------------------------------
function echo(AMessages) {
    var _Message = '';
    for (var _Index = 0; _Index < arguments.length; _Index++) {
        _Message += arguments[_Index];
    }
    WScript.Echo(_Message);
}



/// ---------------------------------------------------------------------------
/// <summary>縦横変換</summary>
/// ---------------------------------------------------------------------------
function transpose(ATable) {
    var _MaxColumns = 0;
    
    
    // 最大列数を取得
    for (var _RowIndex = 0; _RowIndex < ATable.length; _RowIndex++) {
        if (_MaxColumns < ATable[_RowIndex].length) _MaxColumns = ATable[_RowIndex].length;
    }
    
    
    // 縦横変換テーブルの初期化
    var _Table = new Array(_MaxColumns);
    for (var _RowIndex = 0; _RowIndex < _Table.length; _RowIndex++) {
        _Table[_RowIndex] = new Array(ATable.length);
        
        for (var _ColIndex = 0; _ColIndex < _Table[_RowIndex].length; _ColIndex++) {
            _Table[_RowIndex][_ColIndex] = '';
        }
    }
    
    
    // 縦横変換
    for (var _RowIndex = 0; _RowIndex < ATable.length; _RowIndex++) {
        
        for (var _ColIndex = 0; _ColIndex < ATable[_RowIndex].length; _ColIndex++) {
            _Table[_ColIndex][_RowIndex] = ATable[_RowIndex][_ColIndex];
        }
        
    }
    
    
    return _Table;
}



var _Table = [];
_Table.push(['1A', '1B', '1C']);
_Table.push(['2A', '2B', '2C']);
_Table.push(['3A', '3B']);
_Table.push(['4A', '4B', '4C']);
_Table.push(['5A', '5B', '5C']);
_Table.push(['6A', '6B', '6C', '6D']);


echo('縦横変換(入替前)');
for (var _RowIndex = 0; _RowIndex < _Table.length; _RowIndex++) {
    echo(_Table[_RowIndex].join(","));
}


echo('');
echo('');
echo('縦横変換(入替後)');


_Table = transpose(_Table);
for (var _RowIndex = 0; _RowIndex < _Table.length; _RowIndex++) {
    echo(_Table[_RowIndex].join('\t'));
}

拡張子を取得する

/// ---------------------------------------------------------------------------
/// <summary>拡張子を戻す</summary>
/// ---------------------------------------------------------------------------
function getFileExtension(AFileName) {
    
    var startExtensionIndex = AFileName.lastIndexOf('.');
    
    if (startExtensionIndex < 0) return '';
    if (startExtensionIndex == 0) return '';
    
    return AFileName.substring(startExtensionIndex + 1);
}

拡張子を除いたベース名を取得する

/// ---------------------------------------------------------------------------
/// <summary>拡張子を除いたベース名を戻す</summary>
/// ---------------------------------------------------------------------------
function getFileNameWithoutExtension(AFileName) {
    
    var startExtensionIndex = AFileName.lastIndexOf('.');
    
    if (startExtensionIndex < 0) return AFileName;
    if (startExtensionIndex == 0) return '';
    
    return AFileName.substring(0, startExtensionIndex);
}

テンプレート

その他

スクリプトと同じフォルダ内にあるファイルを取得する

var _Directory = WScript.ScriptFullName.replace(/[\\\/]([^\\\/]+)$/, '');
var _FileSystem = new ActiveXObject('Scripting.FileSystemObject');

var _Folder = _FileSystem.GetFolder(_Directory);
var _Files = new Enumerator(_Folder.files);


for (null; !_Files.atEnd(); _Files.moveNext()) {
    WScript.Echo(_Files.item());
}

トップ   一覧 検索 最終更新   ヘルプ   最終更新のRSS