Run script against every file in a directory

C

Chris Gallagher

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
 
M

Mohit Sindhwani

Chris said:
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
What kind of silly errors? What is not working?

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

Michael Linfield

Chris said:
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.
 
P

Pierre-Charles David

2007/9/16 said:
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}") }
 

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,596
Members
45,139
Latest member
JamaalCald
Top