Noftiy该文件被删除 [英] Noftiy that file is deleted

查看:93
本文介绍了Noftiy该文件被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从保存的位置删除当前活动文件时,如何通知用户.

谢谢!

How can I notify the user when the currently active file is deleted from the saved location.

Thank you!

推荐答案

Subhash,

我不太确定当前活动文件"的含义,但是如果您想获得有关文件更改的通知,可以使用FileSystemWatcher类来通知文件更改,重命名,移动和删除.它使您可以处理所有此类事件.

示例:

Hi Subhash,

I''m not quite sure what you mean by "currently active file", but if you want to get notified of file changes, renames, moves and deletions on way to go is to use the FileSystemWatcher class. It lets you handle all these kind of events.

Example:

class Program
{
    private static FileSystemWatcher fw;
    static void Main(string[] args)
    {
        String path = args[0];
        String filter = args[1];

        fw = new FileSystemWatcher(path, filter);
        fw.Deleted += new FileSystemEventHandler(fw_Deleted);

        fw.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime |
                          NotifyFilters.DirectoryName | NotifyFilters.FileName |
                          NotifyFilters.LastAccess | NotifyFilters.LastWrite |
                          NotifyFilters.Security | NotifyFilters.Size;
        fw.IncludeSubdirectories = true;
        fw.EnableRaisingEvents = true;
        Console.ReadLine();
    }

    static void fw_Deleted(object sender, FileSystemEventArgs e)
    {
        Console.WriteLine("{3:yyyy-MM-ddTHH:mm:ss.ffff} Deleted event: {0} {1} {2}", e.Name, e.FullPath, e.ChangeType, DateTime.Now);
    }
}



此控制台应用程序带有两个命令行参数:
1.观看的路径c:\ temp
2.哪些文件扩展名,例如* .txt

干杯


曼弗雷德(Manfred)



This console application takes two command line parameters:
1. the path to watch e.g. c:\temp
2. which file extentions e.g. *.txt

Cheers


Manfred


Heya,

Heya,

/*--[ Function ]-----------------------------------------------------------*/
/*
  Function Name   : FileExist
  Description     : This function checks whether the file specified
                    by txtFilePath exists and returns file status.

  Access Modifier : public
  Param           : -none-

  Retval          : bool   : true  - file exists
                           : false - no such file
*/
/*-------------------------------------------------------------------------*/
public bool FileExist(string txtFilePath)
{
  bool returnValue;
  FileInfo genericFileInfo = new FileInfo(txtFilePath);
  returnValue = genericFileInfo.Exists;
  return returnValue;
}



您可以使用此功能作为检查文件是否退出(未删除)或不退出(已删除)的补充.
希望这对您有用!
请投票!

问候



You can use this function as an addition to checking whether a file exitst (not deleted) or not(deleted).
Hope this was useful!
Please vote!

Regards,


这篇关于Noftiy该文件被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆