[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How get filename from FTP::list

Bazsl

10/16/2007 8:31:00 PM

The following code displays the file's date, time size and name. How can
I access just the file's name from within the block?

@@ftp.list(file_template) do |f|
puts f.name
end


Thanks.

1 Answer

Justin Collins

10/16/2007 11:39:00 PM

0

Bazsl wrote:
> The following code displays the file's date, time size and name. How
> can I access just the file's name from within the block?
>
> @@ftp.list(file_template) do |f|
> puts f.name
> end
>
>
> Thanks.
>

You can use Net:FTP#nlist[1] if you don't need to filter them.
Otherwise I suppose you could do something like:

@@ftp.list(file_template) do |f|
puts f.match(/:\d\d\s(.*)$/)[1]
end

Which works for me. I have no idea if FTP servers vary in their ls output.

-Justin

[1]http://ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/classes/Net/FTP.ht...