using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics; namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
MonitorAndTransferFiles();
Console.ReadLine();
} static string destPath = @"D:\C\ConsoleApplication2\ConsoleApplication2"; static void MonitorAndTransferFiles(string sourcePath=null)
{
sourcePath = Directory.GetCurrentDirectory();
WatchFiles(sourcePath);
} static void WatchFiles(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.NotifyFilter = NotifyFilters.LastWrite|NotifyFilters.CreationTime;
watcher.Filter = "*.*";
watcher.Changed += Watcher_Changed;
watcher.Created += Watcher_Created;
watcher.EnableRaisingEvents = true;
} private static void Watcher_Created(object sender, FileSystemEventArgs e)
{
try
{
Console.WriteLine($"Created:FullPath:{e.FullPath}, ChangeType: {e.ChangeType}");
File.Copy(e.FullPath, Path.Combine(destPath, Path.GetFileName(e.FullPath)), true);
}
catch
{
}
} private static void Watcher_Changed(object sender, FileSystemEventArgs e)
{
try
{
Console.WriteLine($"Changed:FullPath:{e.FullPath}, ChangeType: {e.ChangeType}");
File.Copy(e.FullPath, Path.Combine(destPath, Path.GetFileName(e.FullPath)), true);
}
catch
{
} }
}
}

最新文章

  1. Zen of Python
  2. python统计元素重复次数
  3. Thinkphp源码分析系列(四)–Dispatcher类
  4. android 布局优化常用技巧
  5. PHP中的 extends与implements 区别 [转]
  6. Ubuntu/CentOS使用BIND配置DNS服务器
  7. Elasticsearch简单介绍
  8. Memcached(七)Memcached的并发实例
  9. ArcServer,ArcSDE,ArcIMS,ArcEngine
  10. jquery动态插入行,不用拼写html,简洁版
  11. 关于slideup和slidedown 鼠标多次滑过累积的动画效果
  12. Python中文显示问题
  13. IOS 使用程序外地图(IOS Map and google Map)
  14. Flink 1.3.2 Standalone模式安装
  15. 【Kafka】操作命令
  16. 20160220.CCPP体系详解(0030天)
  17. python 给对象绑定属性和方法和__slots__的使用
  18. java单例模式实例
  19. JavaScript之深浅拷贝
  20. C++的virtual详解

热门文章

  1. pom父工程dependencyManagement中的jar包在子工程中不写版本号无法引入的问题
  2. css实现input表单验证
  3. 使用Python开发小说下载器,不再为下载小说而发愁 #华为云·寻找黑马程序员#
  4. 转:spring aop 拦截业务方法,实现权限控制
  5. 手撕 JVM 垃圾收集日志
  6. 入门级实操教程!从概念到部署,全方位了解K8S Ingress!
  7. Ganglia与Centreon整合构建智能化监控报警平台
  8. Java多态之向上转型
  9. JS页面跳转和打开新窗口方式
  10. layedit添加首行缩进