From: AzimuthDragon Date: 2008-06-10T13:10:40+09:00 Subject: Re: Working with arrays 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" Sent: Monday, June 09, 2008 7:05 PM Newsgroups: comp.lang.ruby To: "ruby-talk ML" 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/. > >