Search code examples
windowsactionscript-3air

AIR- detect directory change Windows desktop


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?


Solution

  • 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