ディレクトリ/ディスクを監視し、ネットワーク共有フォルダから削除されたときに削除されたファイル/フォルダをごみ箱に移動するプログラムをコーディングしようとしています。ネットワーク共有からファイル/フォルダをリサイクルする方法
私はファイル/フォルダが削除されたときに動作していますが、削除を取り消してファイルをごみ箱に移動する必要があります。 How to Move files to the recycle bin
FileSystemWatcher fsw = new FileSystemWatcher();
private void frmMain_Load(object sender, EventArgs e)
{
StartWatcher("X:\\Virtuals\\");
}
private void StopWatcher()
{
if (fsw != null)
try
{
fsw.EnableRaisingEvents = false;
fsw.Dispose();
fsw = null;
}
catch { }
}
private void StartWatcher(string path)
{
StopWatcher();
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = Path.GetDirectoryName(path);
fsw.Filter = Path.GetFileName(path);
fsw.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite | NotifyFilters.FileName
| NotifyFilters.DirectoryName;
fsw.Deleted += new FileSystemEventHandler(OnDeleted);
fsw.EnableRaisingEvents = true;
}
private void OnDeleted(object source, FileSystemEventArgs e)
{ MessageBox.Show("File deleted: " + e.FullPath); }