Run script against every file in a directory

Hi,

I’m currently tryin to implement a ruby script which will run through a
directory of javascript files and run jsmin.rb against each of them as a
part of my build script. im running into a number of silly issues so im
just wondering if theres anyone out there thats done this kind of thing?

Cheers,

Chris

Chris G. wrote:

Hi,

I’m currently tryin to implement a ruby script which will run through a
directory of javascript files and run jsmin.rb against each of them as a
part of my build script. im running into a number of silly issues so im
just wondering if theres anyone out there thats done this kind of thing?

Cheers,

Chris

you would add the code from jsmin.rb (that performs god knows what
purpose) and have that code run against the files…for crawling a
filesystem you would go about it like this:

#!/usr/bin/ruby

require ‘find’

res = []

$stdin.each_line do |file_path|
res << File.size(file_path.strip) #File.size is only an example…
end #I dont know what jsmin.rb contains
#so i cant say what to put there.

#########

usage of this would be as follows

find /etc/ -type f | ./program.rb # where /etc/ would be the directory
that the
# java files are in.

Chris G. wrote:

What kind of silly errors? What is not working?

Cheers,
Mohit.
9/16/2007 | 11:51 PM.

Mohit S. wrote:

Chris

Well in a Unix Shell this would probably do it, as would a for loop with
a bit
of change:

find /directory -name “*.js” -type f -exec jsmin.rb {} ;

In Ruby, I would suggest using ether the Find class or the Filescan gem.
You
can use it to recurse through the directory and then have the ruby
script
execute jsmin.rb with the file name as an argument.

TerryP.

2007/9/16, Chris G. [email protected]:

Hi,

I’m currently tryin to implement a ruby script which will run through a
directory of javascript files and run jsmin.rb against each of them as a
part of my build script. im running into a number of silly issues so im
just wondering if theres anyone out there thats done this kind of thing?

How about this:

Dir[“**/*.js”].each { |js| system(“ruby jsmin.rb #{js}”) }