From: David Gaya Date: 2009-04-21T16:27:22+09:00 Subject: Re: directory watcher, trying to match filename to directory name. > dw = DirectoryWatcher.new "#{@dirwatch}", :interval => 5, :glob => "*/*", :pre_load => true dw = DirectoryWatcher.new "#{@dirwatch}", :interval => 5, :glob => "*/Bob*", :pre_load => true From the documentation: File Selection The directory watcher uses glob patterns to select the files to scan. The default glob pattern will select all regular files in the directory of interest ’*’. Here are a few useful glob examples: '*' => all files in the current directory '**/*' => all files in all subdirectories '**/*.rb' => all ruby files 'ext/**/*.{h,c}' => all C source code files Regards, David 2009/4/21 Brian Wallace : > Hi All, > > Here's an issue I can't seem to figure out, regardless of the hours i've > spent pondering it... > > I'm using Directory Watcher to scan a directory for added files, if files > are added I run my method that handles them.. This works great... > > However.. I'm trying to match the directory name to the file name , ie: > > C:\Send\Bob\Bob* will trigger the event ,but any other file added to that > directory will not ... here's what I have - this will just fire an event for > any file added to the observed folder. > > I set a directory , such as "C:\Send" and then only monitor the > subdirectories of this directory .. I just need to make sure that events are > fired _only_ when the subdirectory name matches the beginning of the file > name. > > dw = DirectoryWatcher.new "#{@dirwatch}", :interval => 5, :glob => "*/*", > :pre_load => true > dw.add_observer {|*args| args.each do |a| > if a.type == :added > sleep(3) > @filename = a.path > signInAction() > getFile(@filename) > initDataUpload(@localFileSize, @session) > completeSend(@fileId, @session) > addDelivery(@localFile, @fileId, @session, @rcpt_email) > puts "File: #{@filename} sent!!!" > @chunkSize = 61440 > end > end > end} > > Any Ideas? > > Thanks, > > Brian >