[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Help on Directory Iteration

Newb Newb

1/27/2009 6:33:00 AM

Hi People i have never done file or Directory manipulations before.
now in my form i have given date field and search button.
if the user enters date and clicks the search button,accoding to the
date entered it has to search for the folder in the ChatHistory folder
for example user enters date like 2009-01-23 means it has to search for
the folder which named 2009-01-23.
if the foder exists again it has to be iterated when i do this i get
error.
folder structure would be ChatHistory has one folder like 2009-01-23
has two folder namely test and user these two folders contain 2 files
each.
My code starts here
if params[:first_name].blank? and params[:second_name].blank? and
!params[:e_date][0].blank? and params[:e_date][1].blank?
puts "frtst date is not blank others are blank"
Dir.foreach("ChatHistory") do |f|
if f == params[:e_date][0]
puts "there:"
Dir.foreach(f) do |p|
puts p
end
end
end



Pls Kindly help me up
--
Posted via http://www.ruby-....

39 Answers

Robert Klemme

1/27/2009 6:50:00 AM

0

On 27.01.2009 07:32, Newb Newb wrote:
> Hi People i have never done file or Directory manipulations before.
> now in my form i have given date field and search button.
> if the user enters date and clicks the search button,accoding to the
> date entered it has to search for the folder in the ChatHistory folder
> for example user enters date like 2009-01-23 means it has to search for
> the folder which named 2009-01-23.
> if the foder exists again it has to be iterated when i do this i get
> error.
> folder structure would be ChatHistory has one folder like 2009-01-23
> has two folder namely test and user these two folders contain 2 files
> each.
> My code starts here
> if params[:first_name].blank? and params[:second_name].blank? and
> !params[:e_date][0].blank? and params[:e_date][1].blank?
> puts "frtst date is not blank others are blank"
> Dir.foreach("ChatHistory") do |f|
> if f == params[:e_date][0]
> puts "there:"
> Dir.foreach(f) do |p|

f does not contain the full path here so you need something like:

Dir.foreach(File.join("ChatHistory",f)) do |p|

Btw, it's often helpful to put a few printing statements here and there
during debugging. :-)

> puts p
> end
> end
> end

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end

Newb Newb

1/27/2009 7:01:00 AM

0


Thanks for the timely reply
--
Posted via http://www.ruby-....

Peña, Botp

1/27/2009 8:11:00 AM

0

RnJvbTogTmV3YiBOZXdiIFttYWlsdG86cmV2YXRoeS5wQGFuZ2xlcml0ZWNoLmNvbV0gDQojICAg
RGlyLmZvcmVhY2goIkNoYXRIaXN0b3J5IikgZG8gfGZ8DQojICAgICBpZiBmID09IHBhcmFtc1s6
ZV9kYXRlXVswXQ0KIyAgICAgICAgcHV0cyAidGhlcmU6Ig0KIyAgICAgICAgRGlyLmZvcmVhY2go
ZikgZG8gfHB8DQojICAgICAgICBwdXRzIHANCiMgICAgICAgIGVuZA0KIyAgICAgZW5kDQojICAg
ZW5kDQoNCmhtbSwgZm9sZGVyL2ZpbG5hbWVzIGFyZSB1bmlxIGZvciBlYWNoIGxldmVsLCBzbyB5
b3Ugc2hvdWxkICpub3QgbmVlZCB0byBpdGVyYXRlIHRoYXQgbm8/IHRoYXQgaXMsDQoNCiAgRGly
LmZvcmVhY2goJ0NoYXRIaXN0b3J5LycrcGFyYW1zWzplX2RhdGVdWzBdKSBkbyB8cGF0aHwNCiAg
ICBwdXRzIHBhdGggdW5sZXNzICV3KC4gLi4pLmluY2x1ZGU/IHBhdGgNCiAgZW5kDQoNCmFuZCBp
IHdvdWxkIGFsc28gcmVmcmFpbiB1c2luZyBwIGFzIGEgdmFyIG5hbWUgOykNCg0K

Newb Newb

1/27/2009 9:47:00 AM

0

Newb Newb wrote:
>
> Thanks for the timely reply

v
--
Posted via http://www.ruby-....

Newb Newb

1/27/2009 9:50:00 AM

0

if params[:first_name].blank? and params[:second_name].blank? and
!params[:e_date][0].blank? and params[:e_date][1].blank?
puts "frtst date is not blank others are blank"
Dir.foreach("ChatHistory") do |folder_name|
if folder_name == params[:e_date][0]
puts "there:"
puts folder_name
@sub_folder_one = Array.new
Dir.foreach(File.join("ChatHistory",folder_name)) do
|sub_folder_name|
@sub_folder_one << sub_folder_name
end
end
end
end
@sub_folder_one array has two folder names
one is =>
jayabharathy@angleritech.com~Vs~kannan@angleritech.com
second is => testing
14;23;45-jayabharathy@angleritech.com
in this i don't need the folder name which has date in
that.
that i don't need testing
14;23;45-jayabharathy@angleritech.com
but i need
jayabharathy@angleritech.com~Vs~kannan@angleritech.com
how can i do that help me up pls
--
Posted via http://www.ruby-....

Brian Candler

1/27/2009 10:52:00 AM

0

Newb Newb wrote:
> folder structure would be ChatHistory has one folder like 2009-01-23
> has two folder namely test and user these two folders contain 2 files
> each.

You can get a list of all files and subdirectories under a subdirectory
like this:

Dir["ChatHistory/2009-01-23/**/*"]

Note: if you are inserting a value from a parameter, you should sanitise
it first. At least remove /../, although it's safest to allow only valid
values like this:

date = params[:date]
raise "Bad date format" unless date =~ /\A\d\d\d\d-\d\d-\d\d\z/
Dir["ChatHistory/#{date}/**/*"].each do |f|
...
end
--
Posted via http://www.ruby-....

Robert Klemme

1/27/2009 10:26:00 PM

0

On 27.01.2009 10:47, Newb Newb wrote:
> Newb Newb wrote:
>> Thanks for the timely reply
>
> v

?

--
remember.guy do |as, often| as.you_can - without end

ldnayman

1/29/2011 7:18:00 PM

0

On Jan 29, 1:59 pm, gerry <hotkloc...@yahoo.com> wrote:
> On Jan 29, 1:54 pm, gerry <hotkloc...@yahoo.com> wrote:
>
>
>
>
>
> > On Jan 29, 1:23 pm, mike <wizb...@gmail.com> wrote:
>
> > > On Jan 29, 10:03 am, "John T." <jbt...@comcast.net> wrote:
>
> > > > On Jan 29, 12:11 pm, Rob T <rob...@charter.net> wrote:
>
> > > > > I don't get it.  What is the appeal?
>
> > > > > Glad to see 13 "dislikes" compared to only 2 "likes" for this video.
>
> > > > > --
> > > > > Rob T
> > > > > This USENET post sent fromhttp://rgpa...
>
> > > > So it doesn't really appeal to everybody....Fair enough.....
>
> > > >   But,To start calling his employees:
> > > > "Thug headed destructive morons"
> > > > "Can you guys jump off with the games"
> > > >     and wishing they
> > > >  "would get caught on his shorts and pull him down with it"
>
> > > >   Really?!?!?! I mean come on......
>
> > > >   This is just stuff getting smashed....your wishing some one gets
> > > > hurt???!?!?
>
> > > >  I'm A big fan of salvaging games and have brought many projects back
> > > > to life but
> > > >   Knowing Todd, I 'm sure these were beyond repair games most likely
> > > > flood /water victims....
>
> > > >   He would be the last person to destroy saleable inventory that he
> > > > could make money on.
>
> > > >   -John T.
>
> > > Are you kidding? Defending this stupidity? These tards deserve every
> > > bit of negativity they will receive, I hope it destoys there business
> > > like the games they destroyed.- Hide quoted text -
>
> > > - Show quoted text -
>
> > John T   all of those games were salvagable....maybee not totaly cost
> > effective but even if only for the hard to find parts they had...ie,
> > bad girls and LAH, i own both of those titles, not to belittle the
> > other they pitched....some people cant afford A-listers..and would be
> > happy to put one of those back in to operation over time.....as they
> > could afford to do it.these games were all with populated
> > playfeilds....WTF.....as far as flooded goes,  i just bought (last
> > night in fact) a STTNG that was a previous flood, water right up to
> > the bottom of the back box...the guy i bought it from spent a ton of
> > time and money on it,  and i still bought it for a very fair
> > price ...and the game is very nice now, and plays new!......out side
> > of the back box being a little wanged up, which i will be redoing all
> > of that.. this game is nicer than some i have seen for more money
> > elsewhere.....and flood is the worst issue aside from fire....so there
> > is no excusing this at all ,  saying they were junk!  anyway..a
> > completely assembled game junk i dont think so......i didnt see any of
> > TNT's games with char or glowing ember's burning as they were being
> > pitched off the roof........why stick up for douche bags......just
> > dont get it........i'm sure that these guys may have done something
> > nice for somebody  here or there in the past before....and they
> > probably all take care of thier familys just fine......good citizens
> > maybee....but one thing this does demonstrate is that this hobby
> > ultimately means zero to them...just a way to make a buck.......if
> > they had a valued collection at their home and love things the way we
> > all here apparently do....they wouldnt be pitching this shit off the
> > roof.......they would wanna see this stuff go to the right
> > home.....nough said.....- Hide quoted text -
>
> > - Show quoted text -
>
> Gusss we will see peoples opinions when they decide to pitch a AFM or
> a MM off the roof.........cant wait to see those posts....

Do you really think they would do that?

The games they threw off the roof suck. Good riddance and all hail
Todd and TNT for having the balls to rid the world of those terrible
games.

Love the rgp meltdown that ensues every 5 years when Todd destroys
some of his garbage.

airace3065

1/29/2011 7:25:00 PM

0


>
> > > > > I don't get it.  What is the appeal?
>
> > > > > Glad to see 13 "dislikes" compared to only 2 "likes" for this video.
>
> > > > > --
> > > > > Rob T
> > > > > This USENET post sent fromhttp://rgpa...


Throwing useless junk in the trash is one thing, but making a video of
games being destroyed and then posting it to a group such as this is
quite another! These people simply want some attention whether it be
negative or positive; all the comments posted however emotional they
may sound are valid.

PapaJohn

1/29/2011 7:31:00 PM

0

On Jan 29, 11:17 am, ldnayman <ldnay...@aol.com> wrote:
> On Jan 29, 1:59 pm, gerry <hotkloc...@yahoo.com> wrote:
>
>
>
>
>
> > On Jan 29, 1:54 pm, gerry <hotkloc...@yahoo.com> wrote:
>
> > > On Jan 29, 1:23 pm, mike <wizb...@gmail.com> wrote:
>
> > > > On Jan 29, 10:03 am, "John T." <jbt...@comcast.net> wrote:
>
> > > > > On Jan 29, 12:11 pm, Rob T <rob...@charter.net> wrote:
>
> > > > > > I don't get it.  What is the appeal?
>
> > > > > > Glad to see 13 "dislikes" compared to only 2 "likes" for this video.
>
> > > > > > --
> > > > > > Rob T
> > > > > > This USENET post sent fromhttp://rgpa...
>
> > > > > So it doesn't really appeal to everybody....Fair enough.....
>
> > > > >   But,To start calling his employees:
> > > > > "Thug headed destructive morons"
> > > > > "Can you guys jump off with the games"
> > > > >     and wishing they
> > > > >  "would get caught on his shorts and pull him down with it"
>
> > > > >   Really?!?!?! I mean come on......
>
> > > > >   This is just stuff getting smashed....your wishing some one gets
> > > > > hurt???!?!?
>
> > > > >  I'm A big fan of salvaging games and have brought many projects back
> > > > > to life but
> > > > >   Knowing Todd, I 'm sure these were beyond repair games most likely
> > > > > flood /water victims....
>
> > > > >   He would be the last person to destroy saleable inventory that he
> > > > > could make money on.
>
> > > > >   -John T.
>
> > > > Are you kidding? Defending this stupidity? These tards deserve every
> > > > bit of negativity they will receive, I hope it destoys there business
> > > > like the games they destroyed.- Hide quoted text -
>
> > > > - Show quoted text -
>
> > > John T   all of those games were salvagable....maybee not totaly cost
> > > effective but even if only for the hard to find parts they had...ie,
> > > bad girls and LAH, i own both of those titles, not to belittle the
> > > other they pitched....some people cant afford A-listers..and would be
> > > happy to put one of those back in to operation over time.....as they
> > > could afford to do it.these games were all with populated
> > > playfeilds....WTF.....as far as flooded goes,  i just bought (last
> > > night in fact) a STTNG that was a previous flood, water right up to
> > > the bottom of the back box...the guy i bought it from spent a ton of
> > > time and money on it,  and i still bought it for a very fair
> > > price ...and the game is very nice now, and plays new!......out side
> > > of the back box being a little wanged up, which i will be redoing all
> > > of that.. this game is nicer than some i have seen for more money
> > > elsewhere.....and flood is the worst issue aside from fire....so there
> > > is no excusing this at all ,  saying they were junk!  anyway..a
> > > completely assembled game junk i dont think so......i didnt see any of
> > > TNT's games with char or glowing ember's burning as they were being
> > > pitched off the roof........why stick up for douche bags......just
> > > dont get it........i'm sure that these guys may have done something
> > > nice for somebody  here or there in the past before....and they
> > > probably all take care of thier familys just fine......good citizens
> > > maybee....but one thing this does demonstrate is that this hobby
> > > ultimately means zero to them...just a way to make a buck.......if
> > > they had a valued collection at their home and love things the way we
> > > all here apparently do....they wouldnt be pitching this shit off the
> > > roof.......they would wanna see this stuff go to the right
> > > home.....nough said.....- Hide quoted text -
>
> > > - Show quoted text -
>
> > Gusss we will see peoples opinions when they decide to pitch a AFM or
> > a MM off the roof.........cant wait to see those posts....
>
> Do you really think they would do that?
>
> The games they threw off the roof suck. Good riddance and all hail
> Todd and TNT for having the balls to rid the world of those terrible
> games.
>
> Love the rgp meltdown that ensues every 5 years when Todd destroys
> some of his garbage.- Hide quoted text -
>
> - Show quoted text -

Well, like I said before, I purchased a Blackjack from Todd. He was
very fair and upfront with me all during the purchase---I'm in So.
Cal. He seems decicated to this hobby and wouldn't have destroyed any
of those machines had they been salvageable. Maybe you guys should
look up the guys of the past that trashed the machines when they were
only 3 years old inorder to clear them off the market. John