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. ...
随机推荐
- 生活小插曲(长篇连载,持续更新ing)^_^
这个帖子,长期记录一些小小的生活插曲 在北京朋友开店了-关于同学开快餐店的故事.今天下午听说这个朋友在附近开了一个店,下午5点多吧,出门去他那里去了.走路过去的.在那里聊了将近一个小时吧.对最近我们自 ...
- 移动端开发语言的未来的猜想#华为云·寻找黑马程序员#【华为云技术分享】
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...
- 爬虫新宠requests_html 带你甄别2019虚假大学 #华为云·寻找黑马程序员#
python模块学习建议 学习python模块,给大家个我自己不专业的建议: 养成习惯,遇到一个模块,先去github上看看开发者们关于它的说明,而不是直接百度看别人写了什么东西.也许后者可以让你很快 ...
- 【Python成长之路】Python爬虫 --requests库爬取网站乱码(\xe4\xb8\xb0\xe5\xa)的解决方法【华为云分享】
[写在前面] 在用requests库对自己的CSDN个人博客(https://blog.csdn.net/yuzipeng)进行爬取时,发现乱码报错(\xe4\xb8\xb0\xe5\xaf\x8c\ ...
- 华为云ModelArts图深度学习,学习知识还能考取微认证
作为人工智能最前沿的技术之一,图深度学习被公认是人工智能认识世界实现因果推理的关键,也是深度学习未来发展的方向.但深度学习对图数据模型的支持性差一直是众多研究者难以攻克的难点,因此图深度学习在实际生产 ...
- 基于webpack实现多html页面开发框架一 准备工作
本系列主要介绍如何基于webpack实现多html页面开发框架,这里不讲webpack的基本概念,废话不多说,直奔主题! 前置条件: 1.安装node环境,自己去官网下载安装 2.新建文件夹webpa ...
- .NETCore 访问国产达梦数据库
前言 武汉达梦数据库有限公司成立于2000年,为中国电子信息产业集团(CEC)旗下基础软件企业,专业从事数据库管理系统的研发.销售与服务,同时可为用户提供大数据平台架构咨询.数据技术方案规划.产品部署 ...
- Spring代理模式(CGLIB动态代理模式)
jdk动态代理和CGLIB动态代理 没什么太大的区别,CGLIB动态代理不需要接口,但是需要导入jar包. 房东出租房子的方法: package com.bjsxt.proxy2; public cl ...
- 第六章 jQuery选择器
jQuery选择器概述: 选择器jQuery基础,在jQuery中,对事件处理,遍历DOM和Ajax操作都依赖于选择器. 什么是jQuery选择器: jQuery选择器拥有良好的浏览器兼容性,不用使用 ...
- 超简单!asp.net core前后端分离项目使用gitlab-ci持续集成到IIS
现在好多使用gitlab-ci的持续集成的教程,大部分都是发布到linux系统上的,但是目前还是有很大一部分企业使用的都是windows系统使用IIS在部署.NET应用程序.这里写一下如何使用gitl ...