From: Matt Harrison Date: 2011-06-16T21:25:26+09:00 Subject: Re: queues? inotify? anything else? On 16/06/2011 08:07, Robert Klemme wrote: > On Wed, Jun 15, 2011 at 11:58 PM, Matt Harrison > wrote: >> I don't even really know how to describe this problem. I know what I want >> the end result to be, but I've run into a dead end trying to figure out >> possible solutions. >> >> I've got a script which looks for files of a given type in a directory, >> processes them, then moves the result elsewhere and removes the sources. >> >> Currently, if I add another file to the directory while the script is >> running, it will not be noticed (I'm using a simple directory read). >> >> I would like to be able to add file while the script is busy and have it >> append the new filename to its list. I've considered inotify type monitoring >> but I don't know much about it and if it could be made to fit this >> single-threaded script. >> >> I've also thought about re-reading the directory after each file operation >> is complete, and adding the previously unknown filenames to the list. > > In this case you would need to keep track of all files seen already so > you do not add files multiple times. > >> I'm just not sure which way I should begin looking, if there's a good >> solution for this already out there, or...what. >> >> Thanks for some input > > Since your script is single threaded anyway and if you do not want to > change too much you could simply wrap your whole script in a loop > which is terminated if the reading of the directory does not find any > matching files any more, e.g. > > files = nil > > until (files = find_files).empty? > files.each do |f| > process f > move v > end > end > > Kind regards > > robert > Thanks Robert, It's such a simple solution but it's always the easy ones that I tend to overlook.