id:trapemiyaさんのBlog記事のFileSystemWatcherですが、こいつを扱うのは厄介らしいです。 FileSystemWatcherのChangeイベントって複数回発生するのね ということでid:trapemiyaさんの対処方法はChangedイベント発生後10秒間は次のイベントを無視るというものでした。ちょっと対処方法は変わりますが、Rxを使うと10秒間イベントが発生しなかったら・・・といった方法での対応がさくっとできます。 using System; using System.IO; using System.Reactive.Linq; namespace FileWatchTest { class Program { static void Main(string[] args) { // 監視対象のディレクトリ var dir = @"C:\Users\Ka
Windowsで動くtailコマンドを探してて、CODE PROJECTでソースを発見(linux "tail -f" Command in C#.NET)。 でも、C#というか.NETならFileSystemWatcherがあるのになぜファイルサイズで判定してるのが手抜きっぽく感じたのと、-fオプション以外不要ということで結局自作。 指定ファイルから読み込んだテキストをコマンドプロンプトの文字コードにあわせて変換してないのは手抜き。 コード: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace tail { class Program { static void Main(String[] args) { Actio
フォルダ、ファイルの変更を監視するフォルダやファイルが変更されたらすぐにそのことを知るための方法を紹介します。これは、System.IO.FileSystemWatcherクラスを使用すれば簡単にできます。ただしFileSystemWatcherクラスはWindows NT系のOSでしか使えませんので、Windows98/Meでは残念ながらできません。 フォルダまたはファイルが作成されたときにはCreatedイベントが、削除された時にはDeletedイベントが、名前が変更された時にはRenamedイベントが、サイズ、システム属性、最終書き込み時刻、最終アクセス時刻、またはセキュリティアクセス許可が変更されたときにはChangedイベントが発生します。 次の例では、フォルダ"C:\My Documents"内のTXTファイルの作成、削除、名前の変更を監視しています。WaitForChange
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く