指定条件のファイルを次々とダンプしてみる。

先日のファイルリストに続き、条件にあうファイルを列挙でなくダンプしてみる。

なお本日はregexを使ってみる。

#include <boost/regex.hpp>
using namespace std;

string get_file(string fn)
{
  string r = "";
  string a = "";
  cout<<"File Read: "<<fn<<endl;
  ifstream ifs(fn.c_str());
  if(ifs)
  {
    //getline(ifs,a);
    while(!ifs.eof()){
      ifs >> a;
      r += a;
    }
    ifs.close();
  }else{
    r = "ERROR";
  }
  return(r);
}

int main()
{
    boost::regex reg("\\.html");
    string dir = "../WebWiki/";
    string x,y;
    DIR* dp=opendir(dir.c_str());
    if (dp!=NULL)
    {
      struct dirent* dent;
      do{
        dent = readdir(dp);
        if (dent!=NULL)
        {
          if(regex_search(dent->d_name, reg))
          {
            x = dir + "index.html";
            cout<<x<<endl;
            cout<<get_file(x)<<endl;
          }
        }
      }while(dent!=NULL);
      closedir(dp);
    }
}

実行結果がちょっとアレだな。部分だけ。

<example> $ make run|head -4 ./dirlist ../WebWiki/index.html File Read: ../WebWiki/index.html <?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="ja-JP"><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>WebMemo!</title><metaname="generator"content="EmacsMuse"/><metahttp-equiv="Content-Style-Type"content="text/css"/><linkrel="stylesheet"type="text/css"href="index.css"/></head><body><h1>WebMemo!</h1><!—PagepublishedbyEmacsMusebeginshere—><divclass="contents"><dl><dt><ahref="#sec1">お知らせ(重要)</a></dt><dt><ahref="#sec2">最新話題</a></dt><dt><ahref="#sec3">モバイル</a></dt><dt><ahref="#sec4">Javaった世界</a></dt><dt><ahref="#sec5">-:1: syntax error, unexpected '<' <rb>シェル</rb><rp>(</rp><rt>UNIXShell</rt><rp>)</rp>

^ -:1: unknown regexp options - rp -:1: syntax error, unexpected '<' <rb>シェル</rb><rp>(</rp><rt>UNIXShell</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected $end <rb>シェル</rb><rp>(</rp><rt>UNIXShell</rt><rp>)</rp> ^ または処理系</a></dt><dt><ahref="#sec6">-:1: syntax error, unexpected '<' <rb>パソコン</rb><rp>(</rp><rt>Computers</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected '<' <rb>パソコン</rb><rp>(</rp><rt>Computers</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected $end <rb>パソコン</rb><rp>(</rp><rt>Computers</rt><rp>)</rp> ^ </a></dt><dt><ahref="#sec7">-:1: syntax error, unexpected '<' <rb>歌関係</rb><rp>(</rp><rt>Songs</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected '<' <rb>歌関係</rb><rp>(</rp><rt>Songs</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected $end <rb>歌関係</rb><rp>(</rp><rt>Songs</rt><rp>)</rp> ^ </a></dt><dt><ahref="#sec8">-:1: syntax error, unexpected '<' <rb>なんでも</rb><rp>(</rp><rt>Anything</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected '<' <rb>なんでも</rb><rp>(</rp><rt>Anything</rt><rp>)</rp> ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected $end <rb>なんでも</rb><rp>(</rp><rt>Anything</rt><rp>)</rp> ^ </a></dt><dt><ahref="#sec9">DebianGNU/Linux</a></dt><dt><ahref="#sec10">-:1: syntax error, unexpected '<' <rb>ネットワーク関連</... ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected '<' ...ワーク関連</rb><rp>(</rp><rt>forNetworks</rt><rp>)</rp> ... ^ -:1: unknown regexp options - rp -:1: syntax error, unexpected $end ...><rt>forNetworks</rt><rp>)</rp> ... ^ </a></dt><dt><ahref="#sec11">生物の世界</a></dt><dt><ahref="#sec12">データベース</a></dt><dt><ahref="#sec13">娯楽ソフト群</a></dt><dt><ahref="#sec14">古いページ群</a></dt><dt><ahref="#sec15">リンク</a></dt><dd><dl><dt><ahref="#sec16">ブログ</a></dt><dt><ahref="#sec17">楽器関係</a></dt><dt><ahref="#sec18">バイク関連</a></dt></dl></dd><dt><ahref="#sec19">ここは?</a></dt></dl></div><h2><aname="sec1"id="sec1"></a>お知らせ(重要)</h2><pclass="first"> <ahref="http://singlecylinders.shacknet.nu/">→バイク・ツーリング関係は分家にどうぞ</a></p><h2><aname="sec2"id="sec2"></a>最新話題</h2><ul><li><ahref="CarrierNorikae.html">迷っている事は。</a>使用キャリアの再編成。</li><li><ahref="AndroidLayout2.html">Androidアプリのレイアウト実験2</a>Relativeってやつをもう少しやってみる。</li><li><ahref="AndroidLayout.html">Androidアプリのレイアウト実験</a>あれこれやってみる。</li><li><ahref="Mobile2nd.html">予備ケータイについて</a>予備はやっぱり必要だなぁ。</li><li><ahref="androidTitleHide.html">Androidアプリのタイトルを隠す</a>これは必須だね。</li><li><ahref="androidTimerUI.html">AndroidでTimer.ui</a>別スレッドのTimerからUIにアクセスする。</li><li><ahref="androidDownLoadMP3.html">Androidでバイナリをダウンロード</a>細い回線でキャッシュするための第一歩。</li><li><ahref="DirList.html">ファイル一覧づくり</a>あとの事を考えて細工もしてみたり。</li><li><ahref="androidTips2.html">AndroidでWebアクセス</a>とりあえずテキストから。</li><li><ahref="androidTips.html">AndroidでTips</a>MP3中心にいってみよう。</li></ul><p> →<ahref="OldBikkuri.html">過去のネタはこちら</a>。</p><h2><aname="sec3"id="sec3"></a>モバイル</h2> <example>

なーんか改行とかスペースとか整理されちゃってますね。明日はここを何とかしましょう。

うん、今日はここまで。