0

Discovered a class for detecting directory changes but only seems to work on Mac Desktop, NOT Windows.

https://github.com/renz45/Actionscript/tree/master/Air/filesystem

The FileMonitor class only detects changes for single files I believe.

Does anyone know of a way to detect directory changes with AIR on Windows desktop?

Bachalo
  • 6,965
  • 27
  • 95
  • 189
  • i dont see anything in the main class that wouldn't work on Windows. Does the author claim its mac only or are you getting an error? –  Oct 14 '13 at 21:43
  • no error, just doesn't work:). Decided to opt for manual polling on Windows – Bachalo Oct 15 '13 at 22:41

1 Answers1

0

The monitor checks for the modification time of folders only. On Windows the folder modification time update behaviour is very unreliable, try to add a new file, you'll probably see that it updates the folders modification time, while it doesn't when changing the contents of a file.

For a more reliable behaviour you would have to check the modification time of all files and subfolders.

Here's an example, a changed DirectoryMonitor.traverseDirectoryTree method which also includes the files. It's not thoroughly tested, and with a growing number of nested files and folders you might run into performance problems, but in the end it's just an example.

private function traverseDirectoryTree(dir:File):Vector.<File>
{
    var list:Vector.<File> = new Vector.<File>;
    list.push(dir);
    for each (var file:File in dir.getDirectoryListing())
    {
        if(!file.isHidden)
        {
            list.push(file);
            if(file.isDirectory)
            {
                list = list.concat(traverseDirectoryTree(file));
            }
        }
    }

    return list;
}

See also

Community
  • 1
  • 1
ndm
  • 59,784
  • 9
  • 71
  • 110