惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - pdfw

如何预编译ASP.Net程序 asp.net 输入框在chrome中无法关闭自动提示 sql server不能删除数据库,显示错误:正在使用 如何只更新datetime类型字段中的日期 SQL Server插入或修改数据是中文乱码的问题 怎么解决安装SqlServer2008总是提示Restart computer as failed 分页查询的SQL语句 如何使用Microsoft Enterprise Library里面的Log功能 【转】国外C#开源系统一览表 ,C# Open Source 【转】.NET试题总结二 【转】.NET试题总结一 窗口之间传递消息的一个方法 Dataset Designer在VS 2008里面不工作的解决办法 Flex中查找XML节点 - pdfw - 博客园 如何在非英文环境中正确显示数字 SQL Server Express中连接字符串的问题 wpf制作毛玻璃效果按钮的代码 WPF中用于Path的Geometry Mini-Language 如何跨线程访问UI控件
c#如何监视文件或者文件夹的变化 - pdfw - 博客园
pdfw · 2010-02-10 · via 博客园 - pdfw

可以使用FileSystemWatcher类来监视文件或者文件夹的变化。

下面的代码可以用来监视重命名的行为。

FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\MyDirectory";
watcher.Renamed += new RenamedEventHandler(watcher_Renamed)
watcher.EnableRaisingEvents = true;

void watcher_Renamed(object sender, RenamedEventArgs e)
{
  Console.WriteLine("File Renamed: Old Name: " + e.OldName +
    " New Name: " + e.Name);
}    

 

FileSystemWatcher类的其他事件如下:

watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Created);

这些事件都传递一个 FileSystemEventArgs参数,这个参数包含 filename, full path, what action caused the event 等信息.