[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Run script against every file in a directory

Chris Gallagher

9/16/2007 3:47:00 PM

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
--
Posted via http://www.ruby-....

4 Answers

Mohit Sindhwani

9/16/2007 3:52:00 PM

0

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

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



Terry Poulin

9/16/2007 5:07:00 PM

0

Mohit Sindhwani wrote:
> Chris Gallagher 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
>>

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.


--

Email and shopping with the feelgood factor!
55% of income to good causes. http://www.ip...


Michael Linfield

9/17/2007 7:15:00 AM

0

Chris Gallagher 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.
--
Posted via http://www.ruby-....

Pierre-Charles David

9/17/2007 5:40:00 PM

0

2007/9/16, Chris Gallagher <cgallagher@gmail.com>:
> 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}") }

--
http://pc...