WSH(javascript)で、進捗状況を把握するためのクラス

プログレス状況をファイル名とした空のファイルを作成することで、プログレス状況を表示するという動作を実現してくれるクラス。
WSHでは手軽に進捗状況を表示する手段が無い無いと思っていたがこういう手があることに気づいたので作ってみた。

// Class.createが使えないなら、「Progress = Class.create({」の代わりに以下を使う
// Progress = function(){ this.initialize.apply(this,arguments); };
// Progress.prototype = ({
Progress = Class.create({
	initialize: function(max) {
		this.current = 0;
		this.max     = max;
		this.scriptFolder = fso.GetFile(WScript.ScriptFullName).ParentFolder;
		this.progressFile = "";
		
		this.update(0);
	},
	setMax: function(max) {
		this.max = max;
		this.update();
	},
	setCurrent: function(current) {
		this.current = current;
		this.update();
	},
	update: function(updateValue) {
		this.fileDelete();

		if (updateValue) { this.current += updateValue; }

		this.progressFile = "!進捗状況:{0}/{1}.myProgress"
		this.progressFile = this.progressFile.replace("{0}", this._formatZeroNum(this.current, String(this.max).length));
		this.progressFile = this.progressFile.replace("{1}", this._formatZeroNum(this.max    , String(this.max).length));
		fso.OpenTextFile( fso.BuildPath(this.scriptFolder, this.progressFile), 2, true ).Close();
	},
	fileDelete: function() {
		if (this.progressFile != "") { fso.DeleteFile( fso.BuildPath(this.scriptFolder, "*.myProgress") ); }
	},
	_formatZeroNum: function (num, len) {
		var addZeroStr = "0000000000" + String(num);
		return addZeroStr.substring(addZeroStr.length - len);
	}
});



使い方。

var fso = new ActiveXObject("Scripting.FileSystemObject");
var progress = new Progress(10);
for(var i=0; i<10; i++) {
	progress.update(1);
	WScript.Sleep(1000);
};
progress.fileDelete();