Re: Working with arrays
- From: AzimuthDragon <programdragon@xxxxxxxx>
- Date: Mon, 9 Jun 2008 23:10:40 -0500
I'm not an expert and I can't tell you for sure what to do here, in my own
bot I stored file contents in a variable name and then just rewrote the
file, appending whatever I needed to the end of the variables contents and
then writing the variable to the file. Anyways, back to my reason for
responding, aren't globals slow in Ruby? a friend of mine from deviantART is
always nagging about not using global variables... lol. Anyone feel like
correcting him? And why are you passing in exceptions? :?
--------------------------------------------------
From: "Clement Ow" <clement.ow@xxxxxxxxxxxxxxxxxxx>
Sent: Monday, June 09, 2008 7:05 PM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@xxxxxxxxxxxxx>
Subject: Working with arrays
Hi, people I know some of ya might find me familiar but, I really am
still a novice in ruby thus i'll need help once in awhile. I'd
defeinitely appreciate whatever help that is rendered! =)
ok, so back to our topic. I have a code where I would like to traverse
into files and folders and then at the same time pass in exceptions and
then after that select the whole load of files to carry out actions like
copying or deleting. But I'll only need help for the traversing of
folders and the exceptions part. Here's my code:
src1 = []
$source.each do |y|
Find.find(y + "/") do |file|
src1 << file
$file_exception[i].each do |ex|
src1.delete_if {|x| /#{ex}/ =~ File.basename(file)}
end
end
$source is an array of source paths like ["C:/Del", "C:/My Pictures"]
$file_exception is an array of exceptions like [".txt", ".xls"]
The whole block of code is working fine except that it traverses into
the folders twice, and then parses all the file paths into src1(which is
not what is wanted) Is there any way to improve on my code?
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Working with arrays
- From: Clement Ow
- Re: Working with arrays
- References:
- Working with arrays
- From: Clement Ow
- Working with arrays
- Prev by Date: Re: Ruby-Postgres connection with libdbd-pg-ruby library
- Next by Date: Re: GUI library/framework?
- Previous by thread: Working with arrays
- Next by thread: Re: Working with arrays
- Index(es):
Relevant Pages
|