Find.prune if ( filename[-5,5] != ".java") is odd?

M

Martin Elzen

Hi all.

Today I had to do a recursive touch on all Java files in a certain director=
y. 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 j=
ust changed the script a bit and now it does work as intended, but... I re=
ally 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 =3D=3D "."
Find.prune if (filename.size < 6) # shortest interesting filename =3D=3D =
"a.java"

# first try, if I don't comment-out the following line it just does not w=
ork as intended...
#Find.prune if ( filename[-5,5] !=3D ".java") # string doesn't end with "=
java" ?
#`touch #{filename}`


`touch #{filename}` if filename[-5,5] =3D=3D ".java"=20

end
 
J

Jason Roelofs

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

What about:

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

Jason
 
K

Ken Bloom

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top