# Find.prune if ( filename!= ".java") is odd?

**URL:** <https://www.ruby-forum.com/t/find-prune-if-filename-java-is-odd/135837>\
**Category:** Ruby\
**Created:** [April 25, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/find-prune-if-filename-java-is-odd/135837 "2008-04-25T14:30:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [April 25, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/find-prune-if-filename-java-is-odd/135837/1 "2008-04-25T14:30:01Z")

</div>

Hi all.

Today I had to do a recursive touch on all Java files in a certain  
directory. Since I recently found that super cool ruby Find example I  
figured I’d use that. However, my first try at a solution didn’t work.  
In the end I just changed the script a bit and now it does work as  
intended, but… I really don’t understand why the first version of the  
example didn’t work… It’s the Ruby 1.8.6 1-click-installer version,  
if that matters.

require “find”

Find.find( “c:/usd70.senior.2008.04.14.copy” ) do |filename|  
Find.prune if filename == “.”  
Find.prune if (filename.size \< 6) # shortest interesting filename ==  
“a.java”

# first try, if I don’t comment-out the following line it just does

not work as intended…  
#Find.prune if ( filename[-5,5] != “.java”) # string doesn’t end with  
“.java” ?  
#`touch #{filename}`

`touch #{filename}` if filename[-5,5] == “.java”

end

---

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [April 25, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/find-prune-if-filename-java-is-odd/135837/2 "2008-04-25T16:42:11Z")

</div>

On Fri, Apr 25, 2008 at 8:28 AM, Martin E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Find.prune if filename == “.”

What about:

Dir[“c:/usd70.senior.2008.04.14.copy/\*\*/\*.java”].each { |f| `touch #{f}`  
}

Jason

---

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [April 25, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/find-prune-if-filename-java-is-odd/135837/3 "2008-04-25T17:41:02Z")

</div>

On Fri, 25 Apr 2008 07:28:42 -0500, Martin E. wrote:

> string doesn’t end with “java” ? #`touch #{filename}`
> 
> `touch #{filename}` if filename[-5,5] == “.java”
> 
> end

Find.prune is the wrong tool, period.

Find.find will yield all of the subdirectory names as well, and running  
Find.prune on a subdirectory will prevent Find from descending into that  
subdirectory (thereby saving time and ignoring its contents). But  
Find.prune will _not_ jump to the next iteration of the loop. It will  
continue to the end of the block before moving on to the next file.

So I think you want  
next if …  
instead.
