Flex 3 & Air 2: automatically detects when files in a directory are updated

A crazy idea just fell from the sky and hit me in the head xD. I was wondering if this is possible, and an application that can listen when the user β€œadds” new files to the directory.

Example:

  • The user opens our application.
  • The user adds new files to the desktop (using Microsoft Explorer).
  • Our application automatically detects that new files have been added and are performing a function or something else.

Sounds interesting right?

Perhaps this can be done using a programming language such as Visual Basic, and open the executable using the NativeProcess api and listen to the stdOut event ... (:

Has anyone got an idea to share with us? :)

Thanks Lombardi

+4
source share
3 answers

AIR can handle this initially ...

the FileSystemList class fires the directoryChange event whenever a file in the watched directory changes.

You can even use it to watch disks mount (I think Christian Cantrell showed it)

+1
source

Okay, I think I’m coming, look at this solution! :)

private var CheckDelay:Timer = new Timer(5000, 0); private function InitApp():void { CheckDelay.addEventListener(TimerEvent.Timer, CheckForNewFiles, false, 0, true); CheckDelay.start(); } private function CheckForNewFiles(event:TimerEvent):void { var FS:FileStream = new FileStream(); var Buffer:File = File.applicationStorageDirectory.resolvePath("FilesBuffer.cmd"); FS.open(Buffer, FileMode.Write); FS.writeUTFBytes("cd " + File.desktopDirectory.nativePath + "\r\n" + "dir /on /b > " + File.applicationStorageDirectory.resolvePath("FileList.txt").nativePath); FS.close(); var Process:NativeProcess = new NativeProcess(); var NPI:NativeProcessStartupInfo = NativeProcessStartupInfo(); // What a large name! xD NPI.executable = Buffer; Process.start(NPI); Process..addEventListener(NativeProcessExitEvent.EXIT, ReadFileList, false, 0, true); } private function ReadFileList(event:Event):void { var FS:FileStream = new FileStream(); var Buffer:File = File.applicationStorageDirectory.resolvePath("FilesBuffer.cmd"); FS.open(Buffer, FileMode.Read); var FileData:String = FS.readUTFBytes(FS.bytesAvailable); FS.close(); var FileArray:Array = FileData.split("\r\n"); var TempArray:ArrayCollection = new ArrayColletion(); var TempFile:File; for(var i:int = 0;i<FileArray.length;i++){ TempFile = new File(FileArray[i]); TempArray.addItem(TempFile); } } 

At the end, we got an Array (TempArray), which we could use on a datagrid (for example) with the following types: "extension, File Name, FilePath, etc."

Files are updated every 5 seconds.

And why do we use all this code instead of the simple "File.getDirectoryListing ()"? Since we update our application every 5 seconds, if getDirectoryListing () is used for what, our application will take up much more RAM, as well as the cmd command much faster ... :)

If you have an idea, please share it with us! Thanks !: D

-1
source

1 great solution for Windows: use Visual Studio, create the .net application found here http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx Adobe AIR uses its own process to listen for change events sent using .net

-1
source

All Articles