C# Monitor and transfer or copy the changed or created file to a new location
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的更多相关文章
- ansible copy 模块 changed false 没有变化
在分发配置文件的时候,我用命令ansible big_hosthub -m copy -a "src=/home/clouder/deploy-conf.xml dest=/home/cl ...
- 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 ...
- 如何修改sharepoint中alert发送邮件模板
In my post last week I talked about customizing alert notifications and alert templates. Sometimes y ...
- Efficient data transfer through zero copy
Efficient data transfer through zero copy https://www.ibm.com/developerworks/library/j-zerocopy/ Eff ...
- Copy Control settings
Copy Control settings Skip to end of metadata Created by Rajesh Banka, last modified by Jyoti ...
- 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 ...
- JAVA Zero Copy的相关知识【转】
转自:https://my.oschina.net/cloudcoder/blog/299944 摘要: java 的zero copy多在网络应用程序中使用.Java的libaries在linux和 ...
- 文件Copy和文件夹Copy
文件Copy和文件夹Copy using System.Collections.Generic; using System.Linq; using System.Text; using System. ...
- Observer - IO (File Monitor)
1. 概述 有时被称作发布/订阅模式,观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 2. ...
随机推荐
- 教你如何关闭IIS服务
由于IIS服务器和Apache的默认端口号都是80端口,有时我们需要关闭IIS服务,下面讲讲关闭IIS服务的方法. 方法如下: 1.services.msc,在里面找到一个“World Wid ...
- JS获取当前完整的url地址以及参数的方法
javascript 获取当前 URL 参数的两种方法: //返回的是字符串形式的参数,例如:class_id=3&id=2& function getUrlArgStr(){ var ...
- shell 点命令和source指令
1 shell脚本执行方法 有两种方法执行shell scripts,一种是新产生一个shell,然后执行相应的shell scripts:一种是在当前shell下执行,不再启用其他shell.新产生 ...
- 纯CSS背景噪声.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 漫谈边缘计算(三):5G的好拍档
边缘计算的热度迅速攀升,还有一个不得不提的因素,就是5G的发展. [5G推动云计算从集中化向分布式演进] 在第一篇文章(<漫谈边缘计算(一):边缘计算是大势所趋>)中我提到,传统的云计算技 ...
- CentOS7.4系统下,手动安装MySQL5.7的方法
MySQL数据库应用广泛,尤其对于JAVA程序员,不会陌生.如果在不想采购云数据库的情况下,可以自行安装MySQL数据库.文章将介绍,手动在CentOS7.4环境下,安装MySQL5.7版本的方法. ...
- 一道题反映Java的类初始化过程
Java的类初始化过程: 1. 父类的static成员变量,static语句块. 2. 子类的static成员变量,static语句块. 3. 父类的普通成员变量,构造函数. 4. 子类的普通成员变量 ...
- LightOJ1199 Partition Game
Alice and Bob are playing a strange game. The rules of the game are: Initially there are n piles. A ...
- CSU oj 2092-Space Golf
You surely have never heard of this new planet surface exploration scheme, as it is being carried ou ...
- 搭建本地YUM仓库
YUM介绍 yum(yellow dog updater modified)为多个Linux发行版的软件包管理工具,Redhat RHEL CentOS Fedora YUM主要用于自动安装,升级rp ...