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 { } } } }
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论