I’ve been trying to figure out why this code won’t work… specifically… no ‘renamed’ events are showing up… although the other three events seem to be working fine… is the RenamedEventHandler just not working, or am I missing something obvious here?
using UnityEngine;
using System.Collections;
using System.IO;
public class FileWatcher : MonoBehaviour
{
public string fileToWatch = "*.*";
private FileSystemWatcher watcher;
IEnumerator Start ()
{
watcher = new FileSystemWatcher ();
watcher.Path = Application.streamingAssetsPath;
watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName
| NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.Size;
watcher.Filter = fileToWatch;
watcher.Renamed += new RenamedEventHandler (OnRenamed);
watcher.Changed += new FileSystemEventHandler (OnChanged);
watcher.Created += new FileSystemEventHandler (OnChanged);
watcher.Deleted += new FileSystemEventHandler (OnChanged);
watcher.Error += new ErrorEventHandler(OnError);
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
yield return null;
}
private void OnChanged (object source, FileSystemEventArgs e)
{
WatcherChangeTypes wct = e.ChangeType;
Debug.Log (e.FullPath + ": " + wct.ToString ());
}
private void OnRenamed (object source, RenamedEventArgs e)
{
WatcherChangeTypes wct = e.ChangeType;
Debug.Log ("file " + e.OldFullPath + " renamed to " + e.FullPath + ": " + wct.ToString ());
}
private void OnError(object source, ErrorEventArgs e)
{
Debug.Log("Error detected: " + e.GetException().GetType().ToString());
}
}