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...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
How get filename from FTP::list
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