Hey all,
I’m having trouble with Net::FTP’s dir command. I’m looking to get a
list of all the directories, but instead I get a list of every file
IN every directory, and the permissions and timestamps as well.
Is there any way to fix this?
What method SHOULD I use to get a list of all of the directories?
For Clarification…
ftp.dir(’*/’)
=> Every file in every directory and all the file permissions to
accompany them.
Thanks,
-------------------------------------------------------|
~ Ari
crap my sig won’t fit
directories
2. pull out the last token of each entry which will be the
directory name.
Thanks! But is there a different command I can use to get just the
names? I happen to know that where I’m working, what I first collect
from my ftp.dir(’*’) will be all directories. How can I use that to
my advantage?
aRi
--------------------------------------------|
If you’re not living on the edge,
then you’re just wasting space.
Thanks! But is there a different command I can use to get just the
names? I happen to know that where I’m working, what I first collect
from my ftp.dir(‘*’) will be all directories. How can I use that to
my advantage?
aRi
Well there’s #nlst method (using openbsd site as an example):
require ‘net/ftp’
names = nil
Net::FTP.open(‘ftp.openbsd.org’,‘anonymous’,‘blah’) do |ftp|
ftp.chdir(‘/pub/OpenBSD/4.1’)
names = ftp.nlst(‘*’)
end
p names
That will give you the names of directories and files and links in
the 4.1 directory.
If you want just the directories in a directory, you can do this:
require ‘net/ftp’
dirs = []
Net::FTP.open(‘ftp.openbsd.org’, ‘anonymous’, ‘blah’) do |ftp|
ftp.chdir(‘/pub/OpenBSD/4.1’)
dirs = ftp.ls(‘*’).select { |item| item[0,1]=~/^[l|d]/ }
end
dirs.map! { |item| item.split.last }
p dirs
That will give you just the directory and link names in the 4.1
directory (but not if they have spaces in the name).
That will give you just the directory and link names in the 4.1
directory (but not if they have spaces in the name).
mmmmmm yes it finally makes sense! But when you did your ls… Did
you get the listing of every file IN every directory? Because thats
what I get when I use dir.
aRi
-------------------------------------------|
Nietzsche is my copilot
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.