From: "ara.t.howard" Date: 2007-09-29T07:33:22+09:00 Subject: Re: is there to invoke 'previous' in Find? (or refresh the current path?) On Sep 28, 2007, at 4:05 PM, dtown22@gmail.com wrote: > Hi ara, > > I don't necessarily know that the file is created, since I provide the > directory containing the files to the 3rd party app, and it make not > have successfully modified all the of the files. > sure but if - it modified correctly you can do the move yourself - it did not then simply do nothing or blow up either way it does not seem essential that find picks this file up since you are clobber a file it already found right? > My thought process is something like this: > > 1. traverse down the directory tree, when i reach a specified file > type, i know i have found one of the many directories which contain > the files i want to modify, > 2. pass the directory to the 3rd party app, and it does its thing, and > hopefully the files are modified correctly (even if some or not, i do > not want to stop the script, i would like it to continue on, modifying > and renaming > 3. refresh the current directory, go through each of the files, if the > original file exists, and the modified one, delete the original, and > rename the modified. > 4. back to step 1 > > Hope this clears things up a bit hmmm i'm not following, you say 'pass the directory to the 3rd party app' but your code reads Find.find(startingDir) do |path| if File.directory?(path) next else system("myapp #{path}") puts path if File.basename(path) =~ /^Mod-/ if File.exists?(path.sub('Mod-', '')) File.delete(path.sub('Mod-', '')) end File.rename(path, path.sub('Mod-', '')) end end end so you skip over all directories and only process files? let's assume the app actually does process directories at a time. then the problem is pretty each def has_the_right_kind_of_files entries entries.detect{|entry| entry =~ %r/whatever/} end def scour pathname = '.' if test ?d, pathname glob = File.join pathname, '*' entries = Dir.glob glob if has_the_right_kind_files(entries) system "app #{ pathname }" entries = Dir.glob glob end entries.each{|entry| scour entry} else dirname, basename = File.split pathname match, src = %r/^Mod-(.*)$/.match(basename).to_a if match FileUtils.mv pathname, File.join(dirname, src) end end end not that the above code will work first shot - but you get the idea: simply process the directories *before* recursing into them. cheers. a @ http://drawohara.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama