public ManagedFolder(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } _path = path; _watcher = new FileSystemSafeWatcher(_path, "*.*"); _watcher.Changed += OnChanged; _watcher.Created += OnCreated; _watcher.Deleted += OnDeleted; _watcher.Renamed += OnRenamed; _watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite; _watcher.IncludeSubdirectories = true; _watcher.EnableRaisingEvents = true; }
private ManagedFile(string filepath) { var folder = Path.GetDirectoryName(filepath); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } if (!File.Exists(filepath)) { File.Create(filepath).Close(); } FullPath = filepath; FilePath = Path.GetDirectoryName(filepath); FileName = Path.GetFileName(filepath); Extension = Path.GetExtension(FileName); _watcher = new FileSystemSafeWatcher(FilePath, FileName); _watcher.Changed += OnChanged; _watcher.EnableRaisingEvents = true; _watcher.NotifyFilter = NotifyFilters.LastWrite; }