Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
looping
Tim Wolak
6/13/2008 3:13:00 PM
Can someone explain why my code is stopping after looking at the first
file? There are at least 20 files in this directory and it stops after
checking just one.
require 'net/ftp'
class Download
ftp = Net::FTP.new('ftp.site.com')
ftp.login(user="user", passwd="123")
file = ftp.nlst
file.each do | list |
last = "20080609"
curdate = Time.now.localtime.strftime("%Y%m%d")
yesterday = Time.now - 86400
prevday = yesterday.strftime("%Y%m%d")
t = Time.now
hour = t.hour
if(hour >= 0)
procFile = prevday
elsif(hour < 23)
procFile = curdate
end
#procFile = 20080613
lastProc = last
list.scan(/\d{8}/) do | t |
p [t, procFile, list]
if(t == procFile && list =~ /FutBal\d{8}.txt/)
Dir.chdir("/tmp")
ftp.gettextfile(list, localfile = File.basename(list))
exit
elsif(t != procFile && list !~ /FutBal#{procFile}.txt/)
sleep(1800)
end
end
end
end
--
Posted via
http://www.ruby-...
.
2 Answers
Tim Wolak
6/13/2008 3:25:00 PM
0
>> if(t == procFile && list =~ /FutBal\d{8}.txt/)
>> Dir.chdir("/tmp")
>> ftp.gettextfile(list, localfile = File.basename(list))
>> exit
>
> Perhaps you didn't mean to call "exit?"
>
> -Dana
Even if I take that out it still only reads one file in and skips right
to the sleep not looking at the other files.
Thanks,
Tim
--
Posted via
http://www.ruby-...
.
Tim Wolak
6/13/2008 4:58:00 PM
0
> Is there a naming conflict with the variable "t?" Try changing
>
> list.scan(/\d{8}/) do |t|
>
> to use a different variable.
>
> -Dana
Thanks Dana,
There is not a conflict, when print out the variables used I can see it
reading the first line and then that's all it reads. If write in next
instead of exit it will loop through all the lines. If the test fails
it should hit the sleep instruction which it won't do.
Thanks,
Tim
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
looping
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password