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.
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.
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
endThanks.
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.html#M001055
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs