Hi,
has anyone found solution for using filesystemwatcher or something similar in MAC? I try to monitor if USB-stick has been inserted.
FileSystemWatcher is working in linux and windows, but not in MAC. Events are not raised.
using System;
using UnityEngine;
using System.Collections;
using System.IO;
using System.Security.Permissions;
public class Watcher : MonoBehaviour {
public string fileToWatch = "*.*";
public string Path = "/Volumes";
private FileSystemWatcher watcher;
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
void Start ()
{
watcher = new FileSystemWatcher ();
watcher.Path = Path;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
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;
}
public void OnChanged (object source, FileSystemEventArgs e)
{
WatcherChangeTypes wct = e.ChangeType;
Debug.Log (e.FullPath + ": " + wct.ToString ());
}
public void OnRenamed (object source, RenamedEventArgs e)
{
WatcherChangeTypes wct = e.ChangeType;
Debug.Log ("file " + e.OldFullPath + " renamed to " + e.FullPath + ": " + wct.ToString ());
}
public void OnError(object source, ErrorEventArgs e)
{
Debug.Log("Error detected: " + e.GetException().GetType().ToString());
}
}