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. jquery树形结构

    <div class="tree_content"> <div class="tree_node"> <div class=&qu ...

  2. 双显卡安装Ubuntu 18.04和NVIDIA驱动

    踩坑笔记: 用软碟通制作UBUNTU18.04 LTS启动盘 长按DEL键进入BIOS,关闭Security Boot,设置USB优先启动 在黑白的grub引导界面(第一行是Try Ubuntu- 第 ...

  3. nginx部署安装

    首先需要下载Nginx软件包 nginx软件官方下载地址:[nginx官方下载连接](http://www.nginx.org) 建议选择稳定的软件版本,如果练习使用当然是无所谓,随便什么版本都可以, ...

  4. RDS关系型数据库 入门 01 创建关系型数据库实例【华为云分享】

    [摘要] 关系型数据库(Relational Database Service,简称RDS)是一种基于云计算平台的即开即用.稳定可靠.弹性伸缩.便捷管理的在线关系型数据库服务.RDS具有完善的性能监控 ...

  5. python安装matplotlib:python -m pip install matplotlib报错

    matplotlib是python中强大的画图模块. 首先确保已经安装python,然后用pip来安装matplotlib模块. 进入到cmd窗口下,建议执行python -m pip install ...

  6. SpringBoot入门简介(一)

    1.SpringBoot简介 1.1 什么是Spring 随着动态语言的流行 (Ruby.Groovy.Scala.Node.js),Java 的开发显得格外的笨重:繁多的配置.低下的开发效率.复杂的 ...

  7. Java修炼——继承_super父类对象的引用

    Super是指直接父类对象的引用,可以通过super来访问父类中被子类覆盖的方法和属性. 当你调用子类的构造方法时,系统会默认给你先调用父类的构造方法,然后才会调用子类的构造方法. package c ...

  8. Mysql多实例数据库

    什么是Mysql的多实例? 简单的说,Mysql多实例就是一台服务器上同时开启多个不同的服务端口(如3306.3307)同时运行多个Mysql服务进程,这些服务进程通过不同socket监听不同的服务端 ...

  9. C语言每日一练——第1题

    一.程序功能 程序的功能是:将大于整数m且紧靠m的k个素数存入数组xx.并把in.dat文件的内容输入到程序,并把输出结果输出道out.dat文件夹中例如:若输入17,5 则应该输入:19,23,29 ...

  10. django----orm查询优化 MTV与MVC模型 choice参数 ajax serializers

    目录 orm查询优化 only defer select_related 与 prefetch_related MTV 与 MVC 模型 choice参数 Ajax 前端代码 后端代码 前后端传输数据 ...