|
发表于 2018-9-30 21:42:17
|
来自 中国辽宁大连
百度有一个同步盘,但是右下脚还有图标,感觉也不太好。
可以自己写一个,再利用七牛云存储的免费额度来做一个自己的同步盘,然后发布成服务,跟随系统启动。
下面是代码DEMO,需要的可以根据自己的逻辑来修改一下:
- static void Main(string[] args)
- {
- WatcherStrat(@"E:\Temp", "*.*");
- Console.ReadKey();
- }
- private static void WatcherStrat(string path, string filter)
- {
- FileSystemWatcher watcher = new FileSystemWatcher();
- watcher.Path = path;
- watcher.Filter = filter;
- watcher.Changed += new FileSystemEventHandler(OnProcess);
- watcher.Created += new FileSystemEventHandler(OnProcess);
- watcher.Deleted += new FileSystemEventHandler(OnProcess);
- watcher.Renamed += new RenamedEventHandler(OnRenamed);
- watcher.EnableRaisingEvents = true;
- watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess
- | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
- watcher.IncludeSubdirectories = true;
- }
- private static void OnProcess(object source, FileSystemEventArgs e)
- {
- if (e.ChangeType == WatcherChangeTypes.Created)
- {
- OnCreated(source, e);
- }
- else if (e.ChangeType == WatcherChangeTypes.Changed)
- {
- OnChanged(source, e);
- }
- else if (e.ChangeType == WatcherChangeTypes.Deleted)
- {
- OnDeleted(source, e);
- }
- }
- private static void OnCreated(object source, FileSystemEventArgs e)
- {
- Console.WriteLine("文件新建事件处理逻辑 {0} {1} {2}", e.ChangeType, e.FullPath, e.Name);
- }
- private static void OnChanged(object source, FileSystemEventArgs e)
- {
- Console.WriteLine("文件改变事件处理逻辑{0} {1} {2}", e.ChangeType, e.FullPath, e.Name);
- }
- private static void OnDeleted(object source, FileSystemEventArgs e)
- {
- Console.WriteLine("文件删除事件处理逻辑{0} {1} {2}", e.ChangeType, e.FullPath, e.Name);
- }
- private static void OnRenamed(object source, RenamedEventArgs e)
- {
- Console.WriteLine("文件重命名事件处理逻辑{0} {1} {2}", e.ChangeType, e.FullPath, e.Name);
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|