[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby gem to watch file

Junkone

9/21/2008 1:21:00 AM

is there any gem that will watch for a file and if the file exists, or
changes, can trigger process or event. i am looking for something on
the windows platform only.
appreciate any help.
5 Answers

Docky Wocky

10/11/2007 8:56:00 PM

0

aridzona bullshitters sez:

"Hey Dip-shit...
Why do you hate us for our freedom?.."
________________________
Gee, Bully, I didn't know you were a member of Congress.

I don't hate you. You're too entertaining - especially when you try to
express yourself.


Tim Pease

9/21/2008 3:16:00 AM

0

On Sep 20, 2008, at 7:17 PM, Junkone wrote:

> is there any gem that will watch for a file and if the file exists, or
> changes, can trigger process or event. i am looking for something on
> the windows platform only.
> appreciate any help.
>

Take a look at directory_watcher. It works on all platforms.

http://codeforpeople.rubyforge.org/director...

Blessings,
TwP

Junkone

9/22/2008 3:03:00 PM

0

On Sep 20, 11:15 pm, Tim Pease <tim.pe...@gmail.com> wrote:
> On Sep 20, 2008, at 7:17 PM, Junkone wrote:
>
> > is there any gem that will watch for a file and if the file exists, or
> > changes, can trigger process or event.  i am looking for something on
> > the windows platform only.
> > appreciate any help.
>
> Take a look at directory_watcher. It works on all platforms.
>
> http://codeforpeople.rubyforge.org/director...
>
> Blessings,
> TwP

i tried as you suggested and have a few q.
i am trying to run a ruby prog to execute if there is any new file in
a directory. i started out with the examples but am a little confused
on how to useit.
this prog seems to be looking at the current directory where it is
running and not where i had specificed it to watch with dw.glob.

appreciate any help.

seede


require 'directory_watcher'
dw = DirectoryWatcher.new '.', :pre_load => true
dw.glob = "c:\\temp\\scans\\" # is the directory i want to watch.
dw.add_observer {|*args| args.each {|event| puts event}}
dw.start
gets
dw.stop

Siep Korteling

9/22/2008 10:37:00 PM

0

Junkone wrote:
> On Sep 20, 11:15�pm, Tim Pease <tim.pe...@gmail.com> wrote:
>>
>> Blessings,
>> TwP
>
> i tried as you suggested and have a few q.
> i am trying to run a ruby prog to execute if there is any new file in
> a directory. i started out with the examples but am a little confused
> on how to useit.
> this prog seems to be looking at the current directory where it is
> running and not where i had specificed it to watch with dw.glob.
>
> appreciate any help.
>
> seede
>
(...)
Hm, I can't get it to work either (on WinXP).

require 'directory_watcher'
dw = DirectoryWatcher.new 'D:/temp/'
dw.interval=5
dw.add_observer {|*args| args.each {|event| puts event}}
dw.start
gets
dw.stop

It does display the files ("added 'D:/temp/Pink_Pajamas.amv'" etc), but
after that you can delete, add and edit files without directory_watcher
noticing anything. Is it broken on windows or am I doing something
wrong?

Regards,

Siep


--
Posted via http://www.ruby-....

Tim Pease

9/23/2008 3:53:00 PM

0


On Sep 22, 2008, at 4:36 PM, Siep Korteling wrote:

> Junkone wrote:
>> On Sep 20, 11:15=EF=BF=BDpm, Tim Pease <tim.pe...@gmail.com> wrote:
>>>
>>> Blessings,
>>> TwP
>>
>> i tried as you suggested and have a few q.
>> i am trying to run a ruby prog to execute if there is any new file in
>> a directory. i started out with the examples but am a little confused
>> on how to useit.
>> this prog seems to be looking at the current directory where it is
>> running and not where i had specificed it to watch with dw.glob.
>>
>> appreciate any help.
>>
>> seede
>>
> (...)
> Hm, I can't get it to work either (on WinXP).
>
> require 'directory_watcher'
> dw =3D DirectoryWatcher.new 'D:/temp/'
> dw.interval=3D5
> dw.add_observer {|*args| args.each {|event| puts event}}
> dw.start
> gets
> dw.stop
>
> It does display the files ("added 'D:/temp/Pink_Pajamas.amv'" etc), =20=

> but
> after that you can delete, add and edit files without =20
> directory_watcher
> noticing anything. Is it broken on windows or am I doing something
> wrong?

The whole program is blocking on the "gets".

On the windows platform, all threads block when reading from standard =20=

input. So the "gets" is causing all threads to wait including the =20
directory watcher thread.

Try replacing the "gets" with a "sleep 30" or some other time interval.

Blessings,
TwP=