From: Tim Pease Date: 2009-04-22T00:35:17+09:00 Subject: Re: directory watcher, trying to match filename to directory name. On Tue, Apr 21, 2009 at 6:51 AM, Brian Wallace wrote: > Thanks David, > >  Yes I've read every bit of documentation for Directory Watcher ... I guess > my problem is more of a generic ruby programming problem. > > I'm not sure how to dynamically change the glob pattern ...Since its set > during the creation of the dw object .. Of course I can change it, within > the add_observer block - with a symbol.. But the problem I'm having is > getting the subdirectory name for matching... > > ie: C:\Send has 3 subdirectories > > C:\Send\Bob > C:\Send\Kevin > C:\Send\James > > I want to only match a filename that has "Bob, Kevin, or James" inside its > respective subdirectory. > DirectoryWatcher is not able to do what you need. It only supports glob patterns for matching files, and what you are in need of is regular expressions. The best solution is to implement the regular expression matching inside your observer. def observer_method( *args ) args.each do |event| next unless event.type == :added next unless event.path =~ %r/^#{@directory}\/([^\/]+)\/.*\1.*/ # put your code here end end Also, you have a sleep method in your observer block. I would recommend using the "stable" event if you want to make sure that the file is no longer being modified before operating on it. Blessings, TwP