(ruby)(Windows)(拡張子に対する assoc と ftype の設定を一覧表示させるスクリプト)

 いちいち assocとか ftypeとか打つのがめんどいので一覧表示させるスクリプトを書いてみました 笑)
assocとftypeの標準出力への結果を受け取りパースして
拡張子とftypeと実行コマンドを結びつけて表示させてるだけですね
FE=utf-8 FF=unix
#!ruby -Ku

assoc_res = `assoc`
ftype_res = `ftype`

assoc_res = assoc_res.split("\n")
assocs = []
assoc_res.each{|buf|
	if ( buf == "" ) then next end
	assocs << buf.split('=')
}
assoc_res = nil

ftype_res = ftype_res.split("\n")
ftypes = []
ftype_res.each{|buf|
	if ( buf == "" ) then next end
	ftypes << buf.split('=')
}
ftype_res = nil

assocs.each{|buf|
	serchftype = ftypes.assoc(buf[1])
	if (serchftype == nil) then
		serchftype = [nil, '設定されていません']
	end
	print(
		"\n" <<
		'拡張子   : ' << buf[0] << "\n" <<
		'ftype    : ' << buf[1] << "\n" <<
		'コマンド : ' << serchftype[1] << "\n"
	)
}
 で行けてるかな?と思っていたけど
どうも一部に「ftypeが設定されているけどなぜか『設定されていません』になる」のがいくつかあって
調べてみると ftypeの指定で大文字と小文字が一致してないのがいくつか確認できました

 例としては
assocでは .msc=MSCFile と定義されているのに
ftypeでは mscfile=%SystemRoot%\system32\mmc.exe "%1" %* と定義されているみたいなのですね
ということで、修正してみるとこんな感じかな
#!ruby -Ku

assoc_res = `assoc`
ftype_res = `ftype`

assoc_res = assoc_res.split("\n")
assocs = []
assoc_res.each{|buf|
	if ( buf == "" ) then next end
	buf = buf.split('=')
	assocs << ( [] << buf[1].downcase << buf[0] << buf[1] )
}
assoc_res = nil

ftype_res = ftype_res.split("\n")
ftypes = []
ftype_res.each{|buf|
	if ( buf == "" ) then next end
	buf = buf.split('=')
	ftypes << ( [] << buf[0].downcase << buf[0] << buf[1] )
}
ftype_res = nil

assocs.each{|buf|
	serchftype = ftypes.assoc(buf[0])
	if (serchftype == nil) then
		serchftype = [nil, nil, '設定されていません']
	end
	print(
		"\n" <<
		'拡張子   : ' << buf[1] << "\n" <<
		'ftype    : ' << buf[2] << "\n" <<
		'コマンド : ' << serchftype[2] << "\n"
	)
}
小文字化した要素を追加してそちらで検索を掛けてみる感じですね
Array#assocは便利だけど、「比較する要素を指定出来たり」とか「大文字小文字は無視する」の機能も欲しいところですね