![](/img/trans.png)
[英]How can i use FileSystemWatcher to watch directory if directory not exist?
[英]How can i use FileSystemWatcher to watch for file size changes?
設置觀察者的方法:
private void WatchDirectory()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = userVideosDirectory;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.mp4";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
並告訴您是否有任何更改的事件:
private void OnChanged(object source, FileSystemEventArgs e)
{
dirchanged = true;
}
現在,我正在檢查目錄中是否有新文件。 但是現在我也想觀察並檢查這個新創建的文件大小是否正在更改。 並且當文件大小不再更改時,給出類似“文件已准備好”的信息。
在沒有更多更改之前,我如何實時查看文件大小?
使用文件系統在兩個應用程序之間進行通信時,這是一個非常普遍的問題。 以我的經驗,如果您還有一個標記文件表明“真實”文件已完全寫入,則效果最佳。
SystemA: Writes file theRealFile.txt
SystemA: Writes file theRealFile.rdy (0byte)
SystemB: Watches for .rdy files and then reads theRealFile.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.