.NET filesystemwatcher - was it a file or a directory?

后端 未结 4 2058
北恋
北恋 2020-12-05 13:15

Is there a way to determine with the FSW if a file or a directory has been deleted?

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 13:44

    I temporary use the "Path" function initially, but later in case of not delete I fix it by Directory.Exists. However that doesn't fix the Delete case

    bool isDirectory = Path.GetExtension(e.FullPath) == string.Empty;
    
    
    if (e.ChangeType != WatcherChangeTypes.Deleted)
    {
        isDirectory = Directory.Exists(e.FullPath);
    }
    

提交回复
热议问题