From: Paul Lutus Date: 2006-09-02T09:45:35+09:00 Subject: Re: File.ctime for detecting directory modifications? Eero Saynatkari wrote: > Hi! > > Can anyone tell me if Ruby's File.ctime can be reliably > used to detect if a directory's contents have changed? > > I do not need to know of changes to files, just adds and > deletes of files to/from the directory itself. On Linux, File.ctime(path) can be used on a directory to detect file additions or removals, but not changes to existing files. Example code: #!/usr/bin/ruby path="/temp2" ot = File.ctime(path) while true nt = File.ctime(path) puts "#{path} changed at #{Time.new}" if nt != ot ot = nt sleep 1 end > In case you are curious, I intend to cache the files under > $PATH and only re-access them if a modification has been > detected. Okay, now you are saying "modification", not addition or removal. On Linux, File.ctime won't flag change in the directory when file contents change, only additions or removals. BTW File.mtime and File.ctime appear to act the same under Linux. > Alternative solutions to this are also welcome. You want to monitor a directory of files for changes and act if one or more of them has changed, yes? Why not simply collect stats on all the files periodically, and compare new times with old for each file? -- Paul Lutus http://www.arachnoid.com