石(掘る猫の)Blog

一割の情報、九割の水増し

目次

Blog 利用状況

ニュース

Twitter ID -> maincat

書庫

HTAでファイルのインクリメンタル検索

本ブログはヾ(。・ω・。)ノjavascriptを主題としております。
                                                                     . . . 石掘る猫、過去ログを探索中

ひとつ前のjavascriptエントリーはHTAでファイル一覧を表示する、の補足ですか。
これはいけません(; ̄Д ̄)存在意義が揺らいでいます。

というわけで、今回はHTAでファイル一覧を表示するのコードをベースに改良して、
ファイル名をインクリメンタル検索するサンプルを作ってみました。

 

image

この機能はファイル数が少ないと面白くないので、WINDOWSフォルダで実行
してみました。ばっちしビットマップ画像(拡張子.bmp)が列挙されていますネ。

ソースコードはこんな感じです。

<html>
 <head>
  <style>
  </style>
  <script type="text/javascript">
   var files = [];
   
   var search = function( keyword ) {
    target.innerHTML = "";
    for( var i = 0; i < files.length; i++ ) {
     var file = files[i];
     if( file.Name.match( new RegExp( keyword, "i" ) ) ) {
      target.innerHTML += ( i + 1 ) + ":" + file.Name + "<br />";
     }
    };
   };
   
   onload = function() {
    var fso = new ActiveXObject( "Scripting.FileSystemObject" );
    var folder = fso.GetFolder( location.pathname.match( /.*\\/ )/*"C:\\Windows\\"*/ );
    with( new Enumerator( folder.Files ) ) {
     for( ; !atEnd(); moveNext() ) {
      files.push( item() );
     }
    }
    search( "" );
   };
  </script>
 </head>
 <body>
  <input onkeyup="search(this.value);" />
  <div id="target"></div>
 </body>
</html>

Line.18~28は以下の2行が変更・追加となっています。
 Line.24:ファイル名羅列表示から、グローバル配列filesへの挿入に
 Line.26:初期状態では何も表示されないので空文字列""検索を実行


Line.8~16では検索を行っています。呼ばれるたびに愚直に全ファイルを
正規表現でマッチングし、該当要素を羅列表示しています。
 Line.9:リストを空文字列""でクリアっ
 Line.12:正規表現マッチング、構文違反をすると例外で落ちます><


Line.31のonkeyupではsearch機能をコールしています。キーボードが
離されたタイミング(onkeyup)をとらえているのは、状態変化のイベント
(onchange)だとフォーカスが失われるまで呼ばれずインクリメンタルに
ならないからです。便利さで言えば、どっちも一長一短ですね。


私の作るツールには、どれもインクリメンタル検索コードが入っています。
いろいろ応用できて便利ですよヾ(。・ω・。)ノ便利だよ!

投稿日時 : 2008年7月29日 2:05

コメントを追加

# where can i get prednisone over the counter https://prednisonesnw.com/#
5 mg prednisone daily 2021/11/13 9:44 Prednisone

where can i get prednisone over the counter https://prednisonesnw.com/#
5 mg prednisone daily

# baricitinib coronavirus https://baricitinibrx.com
barikind
2021/12/12 16:31 Buksdldj

baricitinib coronavirus https://baricitinibrx.com
barikind

# buy doxycycline without prescription uk https://doxycyline1st.com/
doxycycline 100 mg 2022/02/26 17:53 Jusidkid

buy doxycycline without prescription uk https://doxycyline1st.com/
doxycycline 100 mg

# Long-Term Effects. What side effects can this medication cause?
https://edonlinefast.com
Read now. All trends of medicament. 2023/02/17 11:51 EdPills

Long-Term Effects. What side effects can this medication cause?
https://edonlinefast.com
Read now. All trends of medicament.

# Long-Term Effects. Best and news about drug.
https://canadianfast.com/
Read information now. Generic Name. 2023/02/20 0:25 CanadaBest

Long-Term Effects. Best and news about drug.
https://canadianfast.com/
Read information now. Generic Name.

# online prescriptions without a doctor https://pillswithoutprescription.pro/# 2023/05/15 5:19 PillsPresc

online prescriptions without a doctor https://pillswithoutprescription.pro/#

# gnc ed pills https://edpill.pro/# - treatment for ed 2023/06/27 16:05 EdPills

gnc ed pills https://edpill.pro/# - treatment for ed

タイトル
名前
URL
コメント