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. ...
随机推荐
- 实战!轻松搭建图像分类 AI 服务
人工智能技术(以下称 AI)是人类优秀的发现和创造之一,它代表着至少几十年的未来.在传统的编程中,工程师将自己的想法和业务变成代码,计算机会根据代码设定的逻辑运行.与之不同的是,AI 使计算机有了「属 ...
- iOS 弹窗alertView使用详解
转自:http://blog.it985.com/4321.html alertView是iOS自带的弹窗通知框,我们来看下默认样式的效果图 下面直接上代码 1 2 3 4 5 - (void)del ...
- pip-get.py安装问题
问题: 安装完成和配置环境之后:输入一个测试命令:pip help 出现下面这个问题. Fatal error in launcher: Unable to create process using ...
- Selenium 4 Python的最佳测试框架
随着Python语言的使用越来越流行,基于Python的测试自动化框架也越来越流行.在项目选择最佳框架时,开发人员和测试人员会有些无法下手.做出选择是应该判断很多事情,框架的脚本质量,测试用例的简单性 ...
- CodeForces1006C-Three Parts of the Array
C. Three Parts of the Array time limit per test 1 second memory limit per test 256 megabytes input s ...
- 纯净版SSM
pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...
- servlet读取请求参数后流失效的问题
在用reset接口的时候,常常会使用request.getInputStream()方法,但是流只能读取一次,一旦想要加上一个过滤器用来检测用户请求的数据时就会出现异常. 在过滤器中通过流读取出用户p ...
- shell 100
1.编写hello world脚本 #!/bin/bash# 编写hello world脚本 echo "Hello World!"2.通过位置变量创建 Linux 系统账户及密码 ...
- 人生苦短,我用Python(1)
1.Python保留字与标识符 保留字是Python语言中一些已经被赋予特定意义的单词,开发程序时,不可以把这些保留字作为变量.函数.类.模块和其他对象的名称来使用. and as assert br ...
- 5个点彻底搞清楚SpringBoot注解
作者:张伯毅 一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfig ...