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
{
} }
}
}

C# Monitor and transfer or copy the changed or created file to a new location的更多相关文章

  1. ansible copy 模块 changed false 没有变化

    在分发配置文件的时候,我用命令ansible big_hosthub  -m copy -a "src=/home/clouder/deploy-conf.xml dest=/home/cl ...

  2. copy the content of a file muliptle times and save as ordered files:

    input: transient.case outputs: transient_1.case, transient_2.case,...transient_101.case ********** n ...

  3. 如何修改sharepoint中alert发送邮件模板

    In my post last week I talked about customizing alert notifications and alert templates. Sometimes y ...

  4. Efficient data transfer through zero copy

    Efficient data transfer through zero copy https://www.ibm.com/developerworks/library/j-zerocopy/ Eff ...

  5. Copy Control settings

    Copy Control settings     Skip to end of metadata   Created by Rajesh Banka, last modified by Jyoti ...

  6. Timer triggered DMA transfer - Delay between requesting the DMA transfer

    Hello, I'm working with a STM32F407 controller board.   Right now, I want to trigger a DMA transfer ...

  7. JAVA Zero Copy的相关知识【转】

    转自:https://my.oschina.net/cloudcoder/blog/299944 摘要: java 的zero copy多在网络应用程序中使用.Java的libaries在linux和 ...

  8. 文件Copy和文件夹Copy

    文件Copy和文件夹Copy using System.Collections.Generic; using System.Linq; using System.Text; using System. ...

  9. Observer - IO (File Monitor)

    1. 概述 有时被称作发布/订阅模式,观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 2. ...

随机推荐

  1. 对于web前端的理解

    对于web前端的理解 其实写这篇文章的首要目的是为了准备一道面试题——你对前端的看法是什么?本文不会仅从技术角度去考虑这个问题,还会依据这个社会的变革去讨论这个问题.本文仅代表个人观点,不喜勿喷. W ...

  2. 鲲鹏性能优化十板斧之前言 | 鲲鹏处理器NUMA简介与性能调优五步法

    鲲鹏处理器NUMA简介 随着现代社会信息化.智能化的飞速发展,越来越多的设备接入互联网.物联网.车联网,从而催生了庞大的计算需求.但是功耗墙问题以功耗和冷却两大限制极大的影响了单核算力的发展.为了满足 ...

  3. Apache服务——个人用户主页功能

    使用Apache服务部署静态网站(二) 个人用户主页功能 Apache服务程序中有个默认未开启的个人用户主页功能,能够为所有系统内的用户生成个人网站,确实很实用哦~ 第1步:开启个人用户主页功能: [ ...

  4. apache thrift 和 apache jersey 记录

    几篇好的入门文档链接: 1. Hello World by Thrift Using Java 2. Thrift 实例 Helloworld 3. Thrift版的Hello World 4. Th ...

  5. luogu P2899 [USACO08JAN]手机网络Cell Phone Network |贪心

    include include include include include include define db double using namespace std; const int N=1e ...

  6. luogu CF16E Fish

    题目描述 有n条鱼,编号从1到n,住在湖里.每天有一对鱼相遇, 彼此相遇的概率是一样的.如果两条标号为i和j的鱼见面,第一只吃了第二只的概率为a{i,j},第二只会吃了第一只的概率为a{j,i}=1- ...

  7. 学习ThinkPHP的第20天--MySQL事务操作、查询事件、一对一关联

    之所以从20天才开始写随笔记是因为之前没搞自己的博客 从20天开始记录我在ThinkPHP中的点点滴滴 1.MySQL事务操作 /**事务操作*/ //startTrans启动事务.rollback回 ...

  8. ef not in

    //not in linq var xx=(from c in measStateDetail where !((from d in breakInstr select d.InstrCode).Co ...

  9. Web 前端学习大纲

    什么是前端? 前端即网站前台部分,也叫前端开发,运行在PC端,移动端等浏览器上展现给用户浏览的网页.随着互联网的发展,HTML5,CSS3,前端框架的应用,跨平台响应式网页设计能够适应各种屏幕分辨率, ...

  10. 用正则表达式【regexp】进行高级搜索数据

    正则表达式介绍 正则表达式是用来匹配文本的特殊字符集合,如果你想从一个文本中提取电话号码而已使用正则表达式,如果你需要查找名字中包含数字的所有文件可以使用正则,如果你你要在文本块中找到所有重复的单词, ...