PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Run script against every file in a directory
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Run script against every file in a directory

Réponse
 
LinkBack Outils de la discussion
Vieux 16/09/2007, 16h47   #1
Chris Gallagher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 16/09/2007, 16h51   #2
Mohit Sindhwani
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Run script against every file in a directory

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.



  Réponse avec citation
Vieux 16/09/2007, 18h07   #3
Terry Poulin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Run script against every file in a directory

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.ippimail.com


  Réponse avec citation
Vieux 17/09/2007, 08h14   #4
Michael Linfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Run script against every file in a directory

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-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 18h40   #5
Pierre-Charles David
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Run script against every file in a directory

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://pcdavid.net/

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11864 seconds with 13 queries