-
大小: 33.72 KB文件類型: .rar金幣: 1下載: 0 次發(fā)布日期: 2024-09-03
- 語言: 其他
- 標(biāo)簽:
資源簡介
可以監(jiān)視本機、局域網(wǎng)內(nèi)某個文件夾的增加、刪除、修改等動作,并可自動復(fù)制文件到指定的文件夾下
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Configuration;
using?System.IO;
namespace?FileSyncUpdate
{
????public?partial?class?Form1?:?Form
????{
????????//GetAddr?getAddr?=?null;
????????public?Form1()
????????{
????????????InitializeComponent();
????????????//getAddr?=?new?GetAddr();
????????????//getAddr.Addr1?=?System.Configuration.ConfigurationManager.AppSettings[“addr1“].ToString();
????????????//getAddr.Addr2?=?System.Configuration.ConfigurationManager.AppSettings[“addr2“].ToString();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????//if?(!System.IO.Directory.Exists(getAddr.Addr1))
????????????//{
????????????//????MessageBox.Show(“監(jiān)視文件獲取失敗“);
????????????//????return;
????????????//}
????????????//this.fileSystemWatcher1.Path?=?getAddr.Addr1;
????????????this.fileSystemWatcher1.Path?=?“d:\\test“;
????????????//this.fileSystemWatcher1.EnableRaisingEvents?=?true;
????????????MessageBox.Show(“已經(jīng)處于被監(jiān)視狀態(tài)!“);
????????}
????????///?
????????///?文件發(fā)生改變
????????///?
????????///?
????????///?
????????private?void?fileSystemWatcher1_Changed(object?sender?System.IO.FileSystemEventArgs?e)
????????{
????????????//modifyFile(e.FullPath);
????????????if?(File.Exists(e.FullPath))
????????????{
????????????????string?filepath?=?e.FullPath;
????????????????int?m?=?filepath.LastIndexOf(“\\“);
????????????????string?ss?=?filepath.Substring(m?+?1);
????????????????string?newPath?=?“E:\\testfile\\“?+?ss;
????????????????File.Copy(e.FullPath?newPath?true);
????????????}
????????}
????????///?
????????///?新增文件
????????///?
????????///?
????????///?
????????private?void?fileSystemWatcher1_Created(object?sender?System.IO.FileSystemEventArgs?e)
????????{
????????????//modifyFile(e.FullPath);
????????????if?(File.Exists(e.FullPath))
????????????{
????????????????string?filepath?=?e.FullPath;
????????????????int?m?=?filepath.LastIndexOf(“\\“);
????????????????string?ss?=?filepath.Substring(m?+?1);
????????????????string?newPath?=?“E:\\testfile\\“?+?ss;
????????????????File.Copy(e.FullPath?newPath?true);
????????????}
????????}
????????///?
????????///?刪除文件
????????///?
????????///?
????????///?
????????private?void?fileSystemWatcher1_Deleted(object?sender?System.IO.FileSystemEventArgs?e)
????????{
????????}
????????///?
????????///?文件重命名
????????///?
????????///?
????????///?
????????private?void?fileSystemWatcher1_Renamed(object?sender?System.IO.RenamedEventArgs?e)
????????{
????????????//modifyFile(e
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????931??2009-03-06?12:15??FileSyncUpdate\FileSyncUpdate.sln
????..A..H.?????15360??2009-05-14?12:44??FileSyncUpdate\FileSyncUpdate.suo
?????文件????????193??2009-03-06?13:10??FileSyncUpdate\FileSyncUpdate\App.config
?????文件???????3320??2009-03-06?12:26??FileSyncUpdate\FileSyncUpdate\FileSyncUpdate.csproj
?????文件???????4470??2009-03-06?13:40??FileSyncUpdate\FileSyncUpdate\Form1.cs
?????文件???????3156??2009-03-06?12:46??FileSyncUpdate\FileSyncUpdate\Form1.Designer.cs
?????文件???????6020??2009-03-06?12:46??FileSyncUpdate\FileSyncUpdate\Form1.resx
?????文件????????473??2009-03-06?13:37??FileSyncUpdate\FileSyncUpdate\Program.cs
?????文件???????1200??2009-03-06?12:14??FileSyncUpdate\FileSyncUpdate\Properties\AssemblyInfo.cs
?????文件???????2882??2009-03-06?12:14??FileSyncUpdate\FileSyncUpdate\Properties\Resources.Designer.cs
?????文件???????5612??2009-03-06?12:14??FileSyncUpdate\FileSyncUpdate\Properties\Resources.resx
?????文件???????1097??2009-03-06?12:14??FileSyncUpdate\FileSyncUpdate\Properties\Settings.Designer.cs
?????文件????????249??2009-03-06?12:14??FileSyncUpdate\FileSyncUpdate\Properties\Settings.settings
?????文件????????354??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\obj\FileSyncUpdate.csproj.FileList.txt
?????文件????????842??2009-03-06?13:27??FileSyncUpdate\FileSyncUpdate\obj\Debug\FileSyncUpdate.csproj.GenerateResource.Cache
?????文件??????20480??2009-03-06?13:40??FileSyncUpdate\FileSyncUpdate\obj\Debug\FileSyncUpdate.exe
?????文件????????180??2009-03-06?13:27??FileSyncUpdate\FileSyncUpdate\obj\Debug\FileSyncUpdate.Form1.resources
?????文件??????28160??2009-03-06?13:40??FileSyncUpdate\FileSyncUpdate\obj\Debug\FileSyncUpdate.pdb
?????文件????????180??2009-03-06?13:27??FileSyncUpdate\FileSyncUpdate\obj\Debug\FileSyncUpdate.Properties.Resources.resources
?????文件??????20480??2009-03-06?13:40??FileSyncUpdate\FileSyncUpdate\bin\Debug\FileSyncUpdate.exe
?????文件????????193??2009-03-06?13:10??FileSyncUpdate\FileSyncUpdate\bin\Debug\FileSyncUpdate.exe.config
?????文件??????28160??2009-03-06?13:40??FileSyncUpdate\FileSyncUpdate\bin\Debug\FileSyncUpdate.pdb
?????文件???????5632??2005-12-08?14:51??FileSyncUpdate\FileSyncUpdate\bin\Debug\FileSyncUpdate.vshost.exe
?????文件????????193??2009-03-06?13:10??FileSyncUpdate\FileSyncUpdate\bin\Debug\FileSyncUpdate.vshost.exe.config
?????目錄??????????0??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\obj\Debug\TempPE
?????目錄??????????0??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\obj\Debug
?????目錄??????????0??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\bin\Debug
?????目錄??????????0??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\Properties
?????目錄??????????0??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\obj
?????目錄??????????0??2009-05-14?12:43??FileSyncUpdate\FileSyncUpdate\bin
............此處省略5個文件信息
評論
共有 條評論