[#293058] Hello, world? (#158) — Matthew D Moss <matthew.moss@...>

The three rules of Ruby Quiz 2:

41 messages 2008/03/01

[#293075] Scan HTML — Tom Arra <turtleman14789@...>

So I am new to Ruby scripting so I am not sure if this is possible or

16 messages 2008/03/01

[#293195] How do I get the server name? — "laredotornado@..." <laredotornado@...>

Hi,

13 messages 2008/03/02

[#293248] Split the string — Sijo Kg <sijo@...>

I have a string

17 messages 2008/03/03

[#293307] Normal For Loop — Cory Cory <cg821105@...>

I'm new to Ruby. Is there such thing as a C++ style (and most others)

16 messages 2008/03/03

[#293327] Class and inheritance — August0866 <august0866@...>

Hi All,

21 messages 2008/03/03

[#293399] Why is this not implemented in Ruby — Damjan Rems <d_rems@...>

16 messages 2008/03/03

[#293407] Question on the Ruby Programming Language Book — Bharat Ruparel <bruparel@...>

I have been reading The Ruby Programming Language book by David Flanagan

11 messages 2008/03/03

[#293445] Better performance than native unix commands? — Ma Sa <ntwrkd@...>

I have an issue with nfs and listing a large amount of files that I am

16 messages 2008/03/04

[#293484] jruby vs mri memory management — "Michal Suchanek" <hramrach@...>

Hello

12 messages 2008/03/04

[#293493] Re: The Ruby Programming Language - what are your thoughts? — coigner <coignerATgmail@...>

On Mon, 03 Mar 2008 22:04:55 -0500, Esmail wrote:

20 messages 2008/03/04
[#293944] Re: The Ruby Programming Language - what are your thoughts? — Clifford Heath <no@...> 2008/03/09

Esmail wrote:

[#293955] Re: The Ruby Programming Language - what are your thoughts? — Dave Thomas <dave@...> 2008/03/09

[#293982] Re: The Ruby Programming Language - what are your thoughts? — Clifford Heath <no@...> 2008/03/10

Dave Thomas wrote:

[#293994] Re: The Ruby Programming Language - what are your thoughts? — James Gray <james@...> 2008/03/10

On Mar 9, 2008, at 7:46 PM, Clifford Heath wrote:

[#293601] collect with index? — Tim Conner <plump4651@...>

simple question: how can I do a collect with index? This should be

13 messages 2008/03/05

[#293715] duplicating characters in a string — Adam Akhtar <adamtemporary@...>

If i have a string "abc" and want to make it like this "aabbcc", how do

30 messages 2008/03/06
[#293720] Re: duplicating characters in a string — Gary Wright <gwtmp01@...> 2008/03/06

[#293723] Re: duplicating characters in a string — Adam Akhtar <adamtemporary@...> 2008/03/06

[#293757] IO#Foreach -- Max line length — Tristin Davis <tristin.colby@...>

I'm trying to emulate the new feature in 1.9 that allows you to specify

13 messages 2008/03/06
[#293762] Re: IO#Foreach -- Max line length — 7stud -- <bbxx789_05ss@...> 2008/03/06

Tristin Davis wrote:

[#293809] Dynamic class thingies? (Okay, not sure how to title this one) — coigner <coignerATgmail@...>

Asking for ideas here but let me preface...

9 messages 2008/03/07

[#293927] Trac - Does it make sense to keep http://trac.edgewall.org/ticket/4315 open? — Ilias Lazaridis <ilias@...>

Response to message [1] on trac.devel (as I cannot write there, due to

13 messages 2008/03/09

[#293986] Offering to work directly for the Ruby community! — Gregory Brown <gregory.t.brown@...>

Hi folks,

21 messages 2008/03/10

[#293996] Re: Best practices for Ruby Meta-programming — John Carter <john.carter@...>

On Thu, 6 Mar 2008, harshal wrote:

10 messages 2008/03/10
[#294029] Re: Best practices for Ruby Meta-programming — "Robert Dober" <robert.dober@...> 2008/03/10

On Mon, Mar 10, 2008 at 4:06 AM, John Carter <john.carter@tait.co.nz> wrote:

[#293999] Reding unicode characters? — dare ruby <martin@...>

Hi friends,

13 messages 2008/03/10

[#294015] newbie question — Frantisek Psotka <frantisek.psotka@...>

is in ruby operator for:

15 messages 2008/03/10

[#294034] Getting files out of a .tar.gz archive — celldee <celldee@...>

Hi,

11 messages 2008/03/10

[#294059] Which is better -- method option or multiple methods? — Trans <transfire@...>

In the case of limited options, like the following example, which is

19 messages 2008/03/10

[#294081] Re: shortcut for x = [x] unless x.is_a?(Array) — Siep Korteling <s.korteling@...>

Aryk Grosz wrote:

11 messages 2008/03/10

[#294111] setting local variables via eval — ara howard <ara.t.howard@...>

16 messages 2008/03/11

[#294192] whats the error here? — Adam Akhtar <adamtemporary@...>

My IDE (aptana rails) seems to complain about syntax with this code

15 messages 2008/03/11
[#294197] Re: whats the error here? — Sebastian Hungerecker <sepp2k@...> 2008/03/11

Adam Akhtar wrote:

[#294210] Yet another Windows installer — Phillip Gawlowski <cmdjackryan@...>

Hello, list.

32 messages 2008/03/12
[#294421] Re: [ANN] Yet another Windows installer — James Tucker <jftucker@...> 2008/03/13

[#294231] sort array by some text — Ma Fe <frytaz@...>

Hi, i have array with file names

18 messages 2008/03/12
[#294233] Re: sort array by some text — "Todd Benson" <caduceass@...> 2008/03/12

On Wed, Mar 12, 2008 at 12:02 AM, Ma Fe <frytaz@gmail.com> wrote:

[#294234] Re: sort array by some text — Ma Fe <frytaz@...> 2008/03/12

well I dont know where in array i have .txt files but its sure that

[#294281] elsunless: Compiles but does not run. Standard? — Fred Talpiot <fredistic@...>

In Ruby:

10 messages 2008/03/12

[#294297] including general variables in modules — Mario Ruiz <mario@...>

I'm trying to create different scenarios so I thought to do something

14 messages 2008/03/12

[#294366] Parametric module or injecting code via class method? — Trans <transfire@...>

Which approach is better: parametric module or an injecting class

20 messages 2008/03/13
[#294474] Re: Parametric module or injecting code via class method? — ara howard <ara.t.howard@...> 2008/03/13

[#294486] Re: Parametric module or injecting code via class method? — Robert Klemme <shortcutter@...> 2008/03/13

On 13.03.2008 20:35, ara howard wrote:

[#294499] Re: Parametric module or injecting code via class method? — ara howard <ara.t.howard@...> 2008/03/13

[#294799] Re: Parametric module or injecting code via class method? — Robert Klemme <shortcutter@...> 2008/03/16

On 14.03.2008 00:42, ara howard wrote:

[#294808] Re: Parametric module or injecting code via class method? — "Sean O'Halpin" <sean.ohalpin@...> 2008/03/16

On Sun, Mar 16, 2008 at 9:30 PM, Robert Klemme

[#294481] use reqex to get the middle character and repeat it — Adam Akhtar <adamtemporary@...>

say i have the string "qxq" and i want to repeat the middle char 4 times

10 messages 2008/03/13

[#294506] What is Ruby's biggest strength ? — Tuan Minh <tanthuyhoang85@...>

I'm learning Ruby an Rails.

34 messages 2008/03/14
[#294592] Re: What is Ruby's biggest strength ? — Jeremy Henty <onepoint@...> 2008/03/14

On 2008-03-14, Avdi Grimm <avdi@avdi.org> wrote:

[#294632] Re: What is Ruby's biggest strength ? — Marc Heiler <shevegen@...> 2008/03/14

> What helps Ruby stronger than other programming languages

[#294634] Re: What is Ruby's biggest strength ? — 7stud -- <bbxx789_05ss@...> 2008/03/15

Marc Heiler wrote:

[#294522] Food Database (#159) — "Matthew Moss" <matthew.moss@...>

Note that because I am traveling tomorrow, I've posted this week's

15 messages 2008/03/14

[#294564] Robert's Ruby Riddle: Methodical Digits — "Robert Dober" <robert.dober@...>

Hi list

10 messages 2008/03/14

[#294573] How to Read Ruby API / Documentation — Chinna Karuppan <chinnakaruppan@...>

Hi,

13 messages 2008/03/14

[#294648] standard library documentation — Tom Cloyd <tomcloyd@...>

An example of a puzzle I've run into many times before -

18 messages 2008/03/15
[#294652] Re: standard library documentation — Tom Cloyd <tomcloyd@...> 2008/03/15

Tom Cloyd wrote:

[#294693] How to make net-ping thread safe? — Laurent Julliard <laurent@...>

Hi,

15 messages 2008/03/15

[#294711] WWW::Mechanize and basic_auth — "Todd A. Jacobs" <tjacobs-sndr-019fdb@...>

I'm trying to get basic authentication to work with Ruby 1.8 and

12 messages 2008/03/15

[#294746] argh! more undocumented mysteries: to_yaml — Tom Cloyd <tomcloyd@...>

Beginner woes, here, no doubt, but woes nevertheless.

29 messages 2008/03/16
[#294749] Re: argh! more undocumented mysteries: to_yaml — Stefano Crocco <stefano.crocco@...> 2008/03/16

On Sunday 16 March 2008, Tom Cloyd wrote:

[#294792] returning text between two markers without markers included — Adam Akhtar <adamtemporary@...>

12 messages 2008/03/16
[#294793] Re: returning text between two markers without markers included — Xavier Noria <fxn@...> 2008/03/16

On Mar 16, 2008, at 21:02 , Adam Akhtar wrote:

[#294794] Re: returning text between two markers without markers inclu — Adam Akhtar <adamtemporary@...> 2008/03/16

Thanks Xavier,

[#294828] For Comment: Gem Browser — "s.ross" <cwdinfo@...>

It occurred to me that the way I was finding Gems was by making notes

23 messages 2008/03/17

[#294849] Ruby "Speedup" hints? — Marc Heiler <shevegen@...>

Anyone of you has a few hints on how to speed up ruby code?

34 messages 2008/03/17
[#294888] Re: Ruby "Speedup" hints? — "Gerardo Santana Gez Garrido" <gerardo.santana@...> 2008/03/17

On Mon, Mar 17, 2008 at 12:42 PM, Marc Heiler <shevegen@linuxmail.org> wrote:

[#294894] Re: Ruby "Speedup" hints? — Paul Brannan <pbrannan@...> 2008/03/17

On Tue, Mar 18, 2008 at 02:17:22AM +0900, Gerardo Santana G?mez Garrido wrote:

[#294919] Re: Ruby "Speedup" hints? — "Gerardo Santana Gez Garrido" <gerardo.santana@...> 2008/03/18

On Mon, Mar 17, 2008 at 6:08 PM, Paul Brannan <pbrannan@atdesk.com> wrote:

[#294859] Test for Internet Connection — Cory Cory <cg821105@...>

Does anyone know a way to test to see if the computer is connected to

16 messages 2008/03/17
[#294872] Re: Test for Internet Connection — Roger Pack <rogerpack2005@...> 2008/03/17

I usually do something like this on my machine

[#295150] combine array(string) to string? — Pat Kiatchaipipat <hb.pat87@...>

str= "ABCDE"

11 messages 2008/03/20

[#295184] extending ruby with C++ — 7stud -- <bbxx789_05ss@...>

I'm using this old (2001) mini tutorial:

17 messages 2008/03/20

[#295212] including instance methods and setting an instance variable — Leon Bogaert <leon@...>

Hi all,

20 messages 2008/03/20
[#295234] Re: including instance methods and setting an instance variable — "David A. Black" <dblack@...> 2008/03/21

Hi --

[#295246] Re: including instance methods and setting an instance varia — Leon Bogaert <leon@...> 2008/03/21

Thanks for the clear explanation David!

[#295255] Re: including instance methods and setting an instance varia — Leon Bogaert <leon@...> 2008/03/21

Can I "connect" with the instance if it get's instanciated? Because I

[#295257] Re: including instance methods and setting an instance varia — Robert Klemme <shortcutter@...> 2008/03/21

On 21.03.2008 11:15, Leon Bogaert wrote:

[#295327] Re: including instance methods and setting an instance varia — Leon Bogaert <leon@...> 2008/03/21

Thanks Robert!

[#295328] Re: including instance methods and setting an instance varia — Leon Bogaert <leon@...> 2008/03/21

This guy: http://www.ruby-forum.com/topic/142444

[#295331] Re: including instance methods and setting an instance varia — "David A. Black" <dblack@...> 2008/03/21

Hi --

[#295358] Re: including instance methods and setting an instance varia — Leon Bogaert <leon@...> 2008/03/22

Ah thanks David.

[#295365] Re: including instance methods and setting an instance varia — Robert Klemme <shortcutter@...> 2008/03/22

On 22.03.2008 09:34, Leon Bogaert wrote:

[#295375] Re: including instance methods and setting an instance varia — "Robert Dober" <robert.dober@...> 2008/03/22

On Sat, Mar 22, 2008 at 11:34 AM, Robert Klemme

[#295376] Re: including instance methods and setting an instance varia — Robert Klemme <shortcutter@...> 2008/03/22

On 22.03.2008 13:43, Robert Dober wrote:

[#295288] dynamically defining a method on an instance that references vars in enclosing scope? — "Christopher J. Bottaro" <cjbottaro@...>

Hello. I want to do this.

9 messages 2008/03/21

[#295443] Sytem hook for instance names? — Jeff Patterson <jeff_patterson@...>

Is there a system hook that allows a method to get an instance's symbol

15 messages 2008/03/23

[#295468] Rich Graphic Interface with Ruby — Diego Bernardes <di3go.bernardes@...>

What is the best way to get a really nice gui in ruby?

11 messages 2008/03/24

[#295472] Bootstrapping Ruby with MinGW: selfhosted and test sandbox! — Luis Lavena <luislavena@...>

Hello List,

33 messages 2008/03/24

[#295476] functions, arguments and changing their value permantently — Adam Akhtar <adamtemporary@...>

Im coming over to Ruby from C++ after a long break from programming. One

9 messages 2008/03/24

[#295500] Beginner's question — Peter Johnsson <avokadoret@...>

This question may be a bit too "simple" for this forum which seems to

15 messages 2008/03/24

[#295591] generating unique random numbers — Jimmy Palmer <modernfossil@...>

I'm trying to generate 8 unique random numbers between 1 and 13.

15 messages 2008/03/25

[#295605] thread.rb — "Adam Bender" <abender@...>

I want to modify the Queue class in thread.rb, so I first searched for

12 messages 2008/03/25

[#295615] Why git instead of mercurial? — "John Wells" <lists@...>

It seems like the hot new thing these days in Ruby-land is to host

45 messages 2008/03/25
[#295623] Re: Why git instead of mercurial? — "Matt Todd" <chiology@...> 2008/03/25

I really don't think the internal implementation has that much

[#295736] Re: Why git instead of mercurial? — James Britt <james.britt@...> 2008/03/25

Matt Todd wrote:

[#295629] numbers of a record in an array — Bu Mihai <mihai.bulhac@...>

a have an array array=["a","b","c","a","b"]

17 messages 2008/03/25

[#295661] Pros and Cons of Ruby vs JRuby for GUI — "Victor Reyes" <victor.reyes@...>

Although I have been using Ruby for awhile, I am really a beginner as I use

11 messages 2008/03/25

[#295712] remove regex matched line question — Ikuta Lin <ikuta_lin@...>

I wrote the code to query a txt file, and tried remove matched line like

13 messages 2008/03/25

[#295714] Is possible Ruby to use CRLF instead of LF? — "Iñaki Baz Castillo" <ibc@...>

SGksIEFGQUlLIFJ1YnkgdXNlcyBMRiA9IFxuIHRvIGRldGVjdCBuZXdsaW5lLiBCdXQgbm93IEkn

11 messages 2008/03/25

[#295761] golf: tabs to bullets — "Martin DeMello" <martindemello@...>

Given:

18 messages 2008/03/25

[#295828] INTERPRETED LANGUAGE — Jitendra Rai <jitendra.vinsol@...>

IS IT NECESSARY FOR AN INTERPRETED LANGUAGE TO BE CASE SENSITIVE?

14 messages 2008/03/26

[#295854] The inject function — Shendelzare Silkwood <zerruellx@...>

I want to add together numbers in an array with the inject command. I

12 messages 2008/03/26

[#295876] "loop do IO.select([io], nil, nil)" eats 95% of CPU, any other way? — "Iñaki Baz Castillo" <ibc@...>

SGksIHdoaWNoIGlzIHRoZSBtb3N0IGVmZmljaWVudCB3YXkgb2YgcmVjZWl2aW5nIGFuZCBwcm9j

14 messages 2008/03/26

[#295881] Sun's Overview of Ruby and JRuby — Veloso <starlover@...>

A very good article

11 messages 2008/03/26

[#296063] Web-based games? — Hal Fulton <hal9000@...>

Who's interested in developing a few web-based games?

25 messages 2008/03/28
[#296090] Re: Web-based games? — "M. Edward (Ed) Borasky" <znmeb@...> 2008/03/28

Hal Fulton wrote:

[#296146] Re: Web-based games? — John Joyce <dangerwillrobinsondanger@...> 2008/03/29

[#296160] Re: Web-based games? — Marc Heiler <shevegen@...> 2008/03/29

> Be careful about intellectual property, especially trademarks,

[#296064] hrpicot - cant extract what i want from page — Adam Akhtar <adamtemporary@...>

Hi im starting to use hrpicot and im having problems extracting

9 messages 2008/03/28

[#296098] Why Ruby do not optimize code at all? — Heesob Park <phasis@...>

Hi,

29 messages 2008/03/28
[#296112] Re: Why Ruby do not optimize code at all? — "Park Heesob" <phasis68@...> 2008/03/28

SGksDQotLS0tLSBPcmlnaW5hbCBNZXNzYWdlIC0tLS0tIA0KRnJvbTogInRzIiA8ZGVjb3V4QG1v

[#296115] Re: Why Ruby do not optimize code at all? — ts <decoux@...> 2008/03/28

Park Heesob wrote:

[#296151] Is ruby is faster than all Object oriented Scripting langs — "bramu.ss@..." <bramu.ss@...>

Hello,

37 messages 2008/03/29

[#296173] Help on best way to gather/sort results [Array/Hash]? — Tony De <tonydema@...>

Greetings ruby fans,

18 messages 2008/03/29
[#296177] Re: Help on best way to gather/sort results [Array/Hash]? — "Todd Benson" <caduceass@...> 2008/03/29

On Sat, Mar 29, 2008 at 12:02 AM, Tony De <tonydema@gmail.com> wrote:

[#296179] Re: Help on best way to gather/sort results ? — Tony De <tonydema@...> 2008/03/29

Todd Benson wrote:

[#296180] Re: Help on best way to gather/sort results ? — Tony De <tonydema@...> 2008/03/29

Tony De wrote:

[#296182] Re: Help on best way to gather/sort results ? — Christian <chippersbox@...> 2008/03/29

Wouldn't you want something like @results.sort {|x, y| y[1] <=> x[1]}?

[#296200] rexml to slow — Bu Mihai <mihai.bulhac@...>

I have an xml file and sometimes i call the find_first_recursive method;

19 messages 2008/03/29
[#296325] Re: rexml to slow — Robert Klemme <shortcutter@...> 2008/03/30

On 29.03.2008 08:46, Bu Mihai wrote:

[#296364] Re: rexml to slow — Bu Mihai <mihai.bulhac@...> 2008/03/30

Robert Klemme wrote:

[#296371] Re: rexml to slow — Robert Klemme <shortcutter@...> 2008/03/30

On 30.03.2008 20:23, Bu Mihai wrote:

[#296379] Re: rexml to slow — Bu Mihai <mihai.bulhac@...> 2008/03/30

Robert Klemme wrote:

[#296205] RubyGems 1.1.0 — Eric Hodel <drbrain@...7.net>

= Announce: RubyGems Release 1.1.0

22 messages 2008/03/29

[#296306] inject's pathological case... — "Just Another Victim of the Ambient Morality" <ihatespam@...>

I'm not sure how I feel about inject's pathological case. What do you

28 messages 2008/03/30
[#296309] Re: inject's pathological case... — 7stud -- <bbxx789_05ss@...> 2008/03/30

Just Another Victim... wrote:

[#296311] Re: inject's pathological case... — 7stud -- <bbxx789_05ss@...> 2008/03/30

Oh, yeah:

[#296331] Re: inject's pathological case... — "Rick DeNatale" <rick.denatale@...> 2008/03/30

On 3/30/08, 7stud -- <bbxx789_05ss@yahoo.com> wrote:

[#296375] GC help — "Joey Marino" <joey.da3rd@...>

I am still running out of memory with my ruby application. For some reason,

15 messages 2008/03/30
[#296376] Re: GC help — Tim Hunter <TimHunter@...> 2008/03/30

Joey Marino wrote:

[#296477] Primes in P? — Charles Zheng <snarles2@...>

There is an algorithm that tests primes with a polynomial running time:

13 messages 2008/03/31

Re: ruby tk -- how do you get it working?

From: 7stud -- <bbxx789_05ss@...>
Date: 2008-03-04 00:02:10 UTC
List: ruby-talk #293434
In case anyone else would like to use it, the following is what I used 
to uninstall all the files installed by the mac one click installer. 
Look how easy it was!

The program produces output while running that identifies each file name 
as either a dir or a file.  If the file name is a dir, it is skipped. If 
the file name is a file, it is deleted.  For files that are deleted, the 
dir containing the file is examined to determine if it is now empty.  If 
the dir is empty, it is deleted.  Here is some sample output:

/users/me/2testing/dir2 is a dir
---Skipping to next file name.
/users/me/2testing/dir2/aaa.txt is a file
---Deleted file: /users/me/2testing/dir2/aaa.txt
examining dir: /users/me/2testing/dir2
---Dir isn't empty.
/users/me/2testing/dir2/test1.txt is a file
---Deleted file: /users/me/2testing/dir2/test1.txt
examining dir: /users/me/2testing/dir2
---Dir isn't empty.
/users/me/2testing/dir2/sub_dir is a dir
---Skipping to next file name.
/users/me/2testing/dir2/sub_dir/bbb.txt is a file
---Deleted file: /users/me/2testing/dir2/sub_dir/bbb.txt
examining dir: /users/me/2testing/dir2/sub_dir
---Dir isn't empty.
/users/me/2testing/dir2/sub_dir/test2.txt is a file
---Deleted file: /users/me/2testing/dir2/sub_dir/test2.txt
examining dir: /users/me/2testing/dir2/sub_dir
---Deleted dir: /users/me/2testing/dir2/sub_dir
examining dir: /users/me/2testing/dir2
---Deleted dir: /users/me/2testing/dir2


The program also writes every file and directory that it deletes to a 
file named:

deleted_files_Mac_One_Click_Installer.txt

so that there is a permanent record of what the program did.  The output 
to the file looks like this:

Deleted Directories:
/users/me/2testing/dir2/sub_dir
/users/me/2testing/dir2

Deleted Files:
/users/me/2testing/dir2/aaa.txt
/users/me/2testing/dir2/test1.txt
/users/me/2testing/dir2/sub_dir/bbb.txt
/users/me/2testing/dir2/sub_dir/test2.txt


Here is the program (I also wrote some comments after the code):

=begin
If you go here:

/Library/Receipts/

and click on:

Ruby One-Click Installer for OSX Tiger.pkg

the installer will launch.  If you then click on File>Show Files
in the Apple menubar, you will see a list of the files installed
by the installer.  To copy all the file names, click anywhere in
the window and hit <apple>A and <apple>C. You can then paste the
file names into a .txt file by hitting <apple>P.

You can also get that list of files here:

/Library/Receipts/Ruby One-Click Installer for OSX 
Tiger.pkg/Contents/Resources$

with this command:

/Library.../Resources$ lsbom -s Ruby\ One-Click\ Installer\ for\ OSX\ 
Tiger.bom
=end



def get_master_file_and_path_to_remove

  puts
  puts <<STR
To delete the files under the directory /usr/local, you will most
likely need 'root permissions'.  Therefore, you need to run this
program using the command:

$ sudo ruby this_program_name.rb
password:  <enter your password>

If you didn't run this program using that command, then exit
the program now.  Would you like to exit now('y' or 'n'):
STR

  answer = gets.strip
  if ['y', 'Y', 'yes'].include?(answer)
    puts
    puts "Program terminated."
    exit(1)
  end

  puts
  puts <<STR
Enter the path to a file that contains the file names you
want to delete(if the path has spaces in it, escape the
spaces with a '\\').  You will be given the opportunity
to exit the program before any actual deleting takes place:
STR

  #File containing all the file names to delete:
  delete_list = gets.strip

  puts
  puts <<STR
Enter the path that should be removed from the front of
the filenames(or hit return for none):
STR

  remove_path = gets.strip
  if remove_path.length == 0
    remove_path = nil
  end

  #Show examples of new file names:
  samples = []
  count = 0
  fname = nil
  IO.foreach(delete_list) do |line|
    fname = extract_fname(line, remove_path) #extract_fname() defined 
below

    if fname
      samples << fname
      count += 1
      break if count > 5
    end
  end

  puts

  #Confirm whether these are the file names that should be deleted:
  puts <<STR
Do the following look like the names of the files you want to
delete(y or n)?\n
STR
  puts samples

  answer = gets.strip
  puts
  if !['y', 'Y', 'yes'].include?(answer)
    puts
    puts "Program terminated."
    exit(1)
  end

  puts <<STR
Are you sure you want to delete all the files?  If you answer yes,
then this program will scour your hard drive for all the file names
contained in the file you entered.  The program will then delete
those files as well as any directories that become empty as a result
of deleting a file.  This program will NOT delete the directory
/usr/local or any higher directories.

The names of all the files and directories that were deleted will
be written to a file called:

'deleted_files_Mac_One_Click_Installer.txt'.

Enter 'y'(for yes) if you want to begin deleting the files now.
Otherwise enter, 'n'(for no) if you want to exit the program:
STR

  answer = gets.strip
  puts
  if !['y', 'Y', 'yes'].include?(answer):
    puts
    puts "Program Terminated"
    exit(1)
  end

  return delete_list, remove_path
end


def extract_fname(line_from_file, path_to_remove=nil)

  #remove any leading and trailing whitespace:
  fname = line_from_file.strip

  if fname.length == 0 #then blank line in file
    return nil

  elsif not path_to_remove
    return fname

  else #then chop the specified path off the start of fname
    if fname == path_to_remove #
      return nil
    end

    len = path_to_remove.length
    if fname[0, len] == path_to_remove  #then fname starts with the path
      fname = fname[len..-1] #remove leading path from fname
      return fname

    else  #fname doesn't start with the specified path
      raise ArgumentError,
           "Cannot remove path:\n\t%s from file name:\n\t%s" %
            [path_to_remove, fname]
    end
  end
end


def delete_file(file_name)
  #If the file name corresponds to a file, delete the file.
  #If the file name is a dir, take no action.
  #If the file name doesn't correspond to an existing file or dir,
  #raise a RuntimeError.

  if File.directory?(file_name)
    printf("%s is a dir\n", file_name)
    puts "---Skipping to next file name."
    return false
  elsif File.file?(file_name)
    printf("%s is a file\n", file_name)
    File.delete(file_name)
    printf("---Deleted file: %s\n", file_name)
    return true
  else
    raise RuntimeError, "No such file or directory - %s" % file_name
  end
end


def delete_empty_dirs(curr_dir, stop_dir)
  #Check whether the current directory that used to contain
  #the deleted file is empty and therefore should be deleted.
  #as well. If the current diretory is deleted, then recursively
  #check the parent directories to see if they are now
  #empty and need deleting.
  #--stop_dir is the furthest up the file hierarchy
  #that this method will delete empty dirs.

  deleted_dirs = []
  while curr_dir != stop_dir
    printf("examining dir: %s\n", curr_dir)

    files_in_dir = Dir.entries(curr_dir)
    #Empty dirs on a mac contain the dirs ".", ".." and possibly a file
    #called ".DS_Store".  A .DS_Store file is created if you ever
    #navigated to the dir using Finder. The .DS_Store file contains view
    #options, icon position info, etc. Ruby will delete a dir if the dir
    #contains only "." and "..", but ruby won't delete a dir if the dir
    #contains the file .DS_Store. Hence the following:
    empty_dir_on_mac = [".", "..", ".DS_Store"]
    extra_files = files_in_dir - empty_dir_on_mac

    if extra_files.length == 0  #then dir needs deleting
      if files_in_dir.include?(".DS_Store")
        full_path = File.join(curr_dir, ".DS_Store")
        File.delete(full_path)
      end

      Dir.delete(curr_dir)
      printf("---Deleted dir: %s\n", curr_dir)
      deleted_dirs << curr_dir

    else
      printf("---Dir isn't empty.\n")
      break  #no need to check parent dirs
    end

    #Get parent dir for the next loop to examine:
    curr_dir = File.dirname(curr_dir)
  end

  return deleted_dirs
end


def log_results(files_deleted, dirs_deleted)
  File.open('deleted_files_Mac_One_Click_Installer.txt', 'w') do |file|
    file.puts("Deleted Directories:")
    file.puts(dirs_deleted)

    file.puts

    file.puts("Deleted Files:")
    file.puts(files_deleted)
  end
end





#------MAIN PROGRAM-----------

delete_list, path_to_remove = get_master_file_and_path_to_remove()

deleted_files = []
deleted_dirs = []

IO.foreach(delete_list) do |a_line|

  #Extract a file name from the line:
  fname = extract_fname(a_line, path_to_remove)
  next if !fname

  #If fname is the name of a file, delete it:
  if delete_file(fname)
    deleted_files << fname
  else #then fname is a dir
    next #A dir doesn't become empty unless you delete a file contained
         #therein, so skip the code below which checks for empty dirs.
  end


  #Delete any directories that are now empty as the result
  #of deleting a file:
  top_dir = '/users/autie/2testing' #don't check directories above this 
one
  dir_name = File.dirname(fname)
  deleted = delete_empty_dirs(dir_name, top_dir)
  deleted_dirs.concat(deleted)

end

#Write the names of all the deleted files and dirs
#to a file:
log_results(deleted_files, deleted_dirs)


===============
**********************
===============

Comments on testing


For testing, I used this hierarchy:
/
--users
-----me
-------2testing
-----------dir2
---------------aaa.txt
---------------test1.txt
---------------sub_dir
-------------------test2.txt
-------------------bbb.txt

This was my list of files to delete:

./users/me/2testing/dir2
./users/me/2testing/dir2/aaa.txt
./users/me/2testing/dir2/test1.txt

./users/me/2testing/dir2/sub_dir
./users/me/2testing/dir2/sub_dir/bbb.txt
./users/me/2testing/dir2/sub_dir/test2.txt


During testing, I used the directory /users/me/2testing as the top 
directory in the code (instead of /usr/local).   After running the 
program and entering the file name with the files to delete and '.' as 
the path to remove, I was left with this hierarchy:

/
--me
----2testing


After getting that to work correctly, I changed the top directory in the 
code to /usr/local, and then I ran the program for real.  When prompted, 
I entered a file name containing all the files that the mac one click 
installer installed, and I entered '.' as the path to remove.

After the program finished deleting all the files, the pre-installed 
ruby, which is version 1.8.2 for me, worked without me doing anything 
else, and ruby tk started working again.












-- 
Posted via http://www.ruby-forum.com/.

In This Thread