From: Brian Wallace Date: 2009-04-21T21:51:47+09:00 Subject: Re: directory watcher, trying to match filename to directory name. --000e0cd3beb2dc64450468101bc4 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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. On Tue, Apr 21, 2009 at 3:27 AM, David Gaya wrote: > > dw =3D DirectoryWatcher.new "#{@dirwatch}", :interval =3D> 5, :glob =3D= > "*/*", > :pre_load =3D> true > dw =3D DirectoryWatcher.new "#{@dirwatch}", :interval =3D> 5, :glob =3D> > "*/Bob*", :pre_load =3D> 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 =92*=92. > Here are a few useful glob examples: > '*' =3D> all files in the current directory > '**/*' =3D> all files in all subdirectories > '**/*.rb' =3D> all ruby files > 'ext/**/*.{h,c}' =3D> 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 fil= es > > 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 th= at > > directory will not ... here's what I have - this will just fire an even= t > 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 event= s > are > > fired _only_ when the subdirectory name matches the beginning of the fi= le > > name. > > > > dw =3D DirectoryWatcher.new "#{@dirwatch}", :interval =3D> 5, :glob =3D= > "*/*", > > :pre_load =3D> true > > dw.add_observer {|*args| args.each do |a| > > if a.type =3D=3D :added > > sleep(3) > > @filename =3D a.path > > signInAction() > > getFile(@filename) > > initDataUpload(@localFileSize, @session) > > completeSend(@fileId, @session) > > addDelivery(@localFile, @fileId, @session, @rcpt_email) > > puts "File: #{@filename} sent!!!" > > @chunkSize =3D 61440 > > end > > end > > end} > > > > Any Ideas? > > > > Thanks, > > > > Brian > > > > --000e0cd3beb2dc64450468101bc4--