Page 1 of 1

Event: "New file in folder"

Posted: Tue Jul 15, 2008 12:49 am
by fhx
Greeting,

I am new to revolution. so, my apologies if this is a stupid question:

I need to create an event as soon as a new file has been written in a specific directory (content written and file closed). Is there any other approach than having a function that is looking periodically (means every 1 sec or shorter) in this specific directory.

I was hoping to have something like:

Code: Select all

on newFile in the directory
 ...
end newFile 
Any suggestions/hints or even code-snippets?

Thanks and best,

Frank

Posted: Tue Jul 15, 2008 10:39 am
by Mark
Hi Frank,

In Mac OS X, you could use a folder action. In Linux, a deamon might do the trick.

I'm not sure about Windows. There might be something similar to folder actions.

What about using a command line instruction to send files to a standalone, or simply drop the files onto the standalone, and have the standalone handle the files and put them into a different folder afterwards (or delete them)?

Best,

Mark

Posted: Tue Jul 15, 2008 11:23 am
by Tim
Hey Frank,

Here is some code that will monitor a folder - I've written it so it all goes in the script of a button at the moment :

Code: Select all

on mouseUp
send "monitorFolder C:\Users\Tim\Desktop" to me in 0 milliseconds
end mouseUp


local sFileList, sMonitoredFolder

on monitorFolder pFolder
   put pFolder into sMonitoredFolder
   send "updateMonitor" to me in 500 milliseconds
end monitorFolder


on updateMonitor
   local tOldFolder
   put the defaultFolder into tOldFolder
   
   set the defaultFolder to sMonitoredFolder
   
   if sFileList is empty then 
      put the long files into sFileList
   end if
   
   
   if the long files <> sFileList then
      put the long files into sFileList
      send "filesChanged" to me in 0 milliseconds
   end if
   set the defaultFolder to tOldFolder
   send "updateMonitor" to me in 500 milliseconds
end updateMonitor



-- You would write this handler to do whatever you wanted to do
-- when something in the folder changes.
on filesChanged
   put the long time & " : Some files have changes in the monitored folder" & return after msg
end filesChanged


Hope this helps as a starting point.

Tim.

Posted: Tue Jul 15, 2008 3:38 pm
by fhx
Thanks,
this really helped.
Best,
Frank

Posted: Tue Jul 15, 2008 7:21 pm
by Garrett
Keep in mind though that trying to find out if the file is still in use may be near impossible natively within Rev. If you need to find out if the file is still in use by another program you may have to seek command line alternatives for that info and use Rev to run the command line app and get it's info.

Posted: Tue Jul 15, 2008 11:39 pm
by SparkOut
At least on Windows, you could try calling "handle.exe" http://technet.microsoft.com/en-us/sysi ... 96655.aspx and parsing the info returned. There's an Expert's Exchange article on using vbscript to do this, which you could fire off from Rev if necessary http://www.experts-exchange.com/Program ... 90324.html