[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Did anyone get DirectoryWatch working?

nkb

10/11/2004 10:16:00 AM

Hi.
I placed the following codes at the bottom of the file DirectoryWatch.rb
and ran it from my command line in WindowsXp. Nothing seems to be
happening even when I change/add/modify files. What am I missing? Thanks.

device_manager = Dir::DirectoryWatcher.new( 'c:/temp', 2 )
device_manager.name_regexp = /^[^.].*\.rb$/

device_manager.on_add = Proc.new{ |the_file, stats_hash|
puts "Hey, just found #{the_file.inspect}!"
# Store something custom
stats_hash[:blorgle] = the_file.foo
}

device_manager.on_modify = Proc.new{ |the_file, stats_hash|
puts "Hey, #{the_file.inspect} just changed."
}

device_manager.on_remove = Proc.new{ |stats_hash|
puts "Whoa, the following file just disappeared:"
stats_hash.each_pair{ |k,v|
puts "#{k} : #{v}"
}
}


device_manager.start_watching()


7 Answers

Hal E. Fulton

10/11/2004 10:21:00 AM

0

nkb wrote:
> Hi.
> I placed the following codes at the bottom of the file DirectoryWatch.rb
> and ran it from my command line in WindowsXp. Nothing seems to be
> happening even when I change/add/modify files. What am I missing? Thanks.

I've never tried it... Gavin can help you. Not sure what time zone he
is in.

Wonder if it's a Windows incompatibility? Does it say what platform he
developed on? I'd guess it was Linux.


Hal



Gavin Kistner

10/11/2004 12:59:00 PM

0

On Oct 11, 2004, at 4:15 AM, nkb wrote:
> I placed the following codes at the bottom of the file
> DirectoryWatch.rb and ran it from my command line in WindowsXp.
> Nothing seems to be happening even when I change/add/modify files.
> What am I missing? Thanks.

Hrm, dunno; didn't do any Windows testing on it. (I developed on MacOS
X.)

I'm bolting off to work right now, but will take a look at it on a
Windows box in about 10 hours and see if I can figure out what's up.


--
(-, /\ \/ / /\/



Gavin Kistner

10/12/2004 3:09:00 AM

0

On Oct 11, 2004, at 4:15 AM, nkb wrote:
> I placed the following codes at the bottom of the file
> DirectoryWatch.rb and ran it from my command line in WindowsXp.
> Nothing seems to be happening even when I change/add/modify files.
> What am I missing? Thanks.

The main problem is that while my library starts a new thread, you need
your code to keep running for that thread to keep running. Your code
would run and then immediately finish. A working example is below; note
in particular the unending while loop, which keeps the main program
running while the DirectoryWatcher thread runs.

An ancillary problem is that my library was not closing the file
references it created and passed around, which meant that on Windows
you couldn't modify or delete the files once it had scanned them once.
I've fixed this problem in version 0.9.6:
http://phrogz.net/RubyLibs/Directory...

Here's a program that I tested to work on Windows; I started it
running, saw it add the files in the 'watch_dir' subdirectory. I opened
a separate command window and updated and renamed files, and removed
them. The stdout output of the program follows its source code:

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
_-_-_-_
file: dw_test.rb
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
_-_-_-_
#!/usr/local/bin/ruby

require 'DirectoryWatcher'
require 'singleton'

class App
include Singleton

@@plugin_dir = 'watch_dir'
@@rescan_delay = 5

def initialize
@watcher = Dir::DirectoryWatcher.new( @@plugin_dir, @@rescan_delay )
@watcher.on_add = Proc.new{ |the_file, stats_hash|
stats_hash[:special_number] = rand(100)
puts "#{the_file.path} has been added; it's been assigned special
number ##{stats_hash[:special_number]}"
}
@watcher.on_modify = Proc.new{ |the_file, stats_hash|
puts "#{the_file.path} (##{stats_hash[:special_number]}) just
changed."
}
@watcher.on_remove = Proc.new{ |stats_hash|
puts "It's time to remove ##{stats_hash[:special_number]}"
}
end

def run
@watcher.start_watching
while true
sleep 60
end
end
end

$app = App.instance
$app.run

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
_-_-_-_
Output
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
_-_-_-_
A:\dwtest> ruby dw_test.rb
watch_dir/foo.txt has been added; it's been assigned special number #76
watch_dir/foo.bar has been added; it's been assigned special number #66
It's time to remove #76
watch_dir/foo.txt has been added; it's been assigned special number #71
watch_dir/foo.txt (#71) just changed.
It's time to remove #71


--
(-, /\ \/ / /\/



djberg96

10/12/2004 2:21:00 PM

0

nkb <nkb@pacific.net.sg> wrote in message news:<416A5D4B.5040806@pacific.net.sg>...
> Hi.
> I placed the following codes at the bottom of the file DirectoryWatch.rb
> and ran it from my command line in WindowsXp.

<snip>

If you don't care about cross platform support, there's also win32-changenotify.

Regards,

Dan

Special Care

12/7/2009 4:55:00 AM

0

IF THERE IS NO FREEDOM, DEMOCRACY, EQUALITY, FAIRNESS in the mother-
infant relationship,
well then how the fuckin jayzizz do you expect to find it anywhere
else?
--------------------------------------------------------------------------------------------
REMEMBERING YOUR OWN INFANCY /
THE FORGOTTEN HORRORS OF THE MOTHER-INFANT RELATIONSHIP /
THE FOUNTAIN OF SORROWS / ORIGINAL SIN:

Your Baby is not a Sack of Potatoes, Mrs !
TEMPORARY LINK OWING TO MISUNDERSTANDING OF HEALING NATURE OF THESE
DOCUMENTS:
http://groups.google.com/group/uk.legal/browse_thread/thread/f916a8f0c045c621/c6203a52e4cef64b#c6203a...

http://docs.google.com/Doc?id=dddp6bt4_1...

Shaking the Baby
http://docs.google.com/Doc?id=dddp6bt4_...

Silence of the Damned
http://docs.google.com/Doc?id=dddp6bt4_...

I Still Miss Someone (reissued / back up copy)
http://docs.google.com/Doc?id=dddp6bt4_1...

Careless Hands
http://docs.google.com/View?id=dddp6bt4_1...

Practical Reparenting - One Step at a Time
http://docs.google.com/Doc?id=dddp6bt4_1...

The Universal Fear of Being Known
http://docs.google.com/View?id=dddp6bt4_1...

The Shame
http://docs.google.com/Doc?id=dddp6bt4_...

Natural Functioning is not Paedophilia
http://docs.google.com/Doc?id=dddp6bt4_...

The Incest Taboo Revisited
http://docs.google.com/Doc?id=dddp6bt4_...

Collective Mental Illness
http://groups.google.com/group/alt.uk.law/msg/fde3e9567813bc7e?&q=collective+ment...

Additional reading [different authors, for information]:
http://www.womanthouartgod.com/breastfeedinglove...

Special Care

12/7/2009 4:57:00 AM

0

IF THERE IS NO FREEDOM, DEMOCRACY, EQUALITY, FAIRNESS in the mother-
infant relationship,
well then how the fuckin jayzizz do you expect to find it anywhere
else?
---------------------------------------------------------------------------­-----------------

Special Care

12/16/2009 5:23:00 AM

0

On Dec 7, 4:57 am, Special Care <special.car...@googlemail.com> wrote:
> IF THERE IS NO FREEDOM, DEMOCRACY, EQUALITY, FAIRNESS in the mother-
> infant relationship,
> well then how the fuckin jayzizz do you expect to find it anywhere
> else?
> ---------------------------------------------------------------------------­­-----------------

Listen to Ulrike Meinhof.
She hasn't a clue.
Headless chicken.
http://www.youtube.com/watch?v=k7jEk_f04pE&featu...
-------------------------------------------------------------------------------------------------
Reducing to Essentials
http://docs.google.com/View?id=dddp6bt4_1...