我正在尝试使用 net-sftp 库创建文件和目录树。
我可以使用 .glob 方法获取文件的递归列表,并且可以使用 .opendir 方法确定其中一个结果是否是目录。
我已经能够创建一个包含文件的哈希和另一个包含目录的哈希,但我希望能够创建一棵树。
files = []
directories = []
sftp.dir.glob("/home/**/**") do |entry|
fullpath = "/home/" + entry.name
file = Hash.new
file[:path] = fullpath
sftp.opendir(fullpath) do |response|
unless response.ok?
files.push(file)
else
directories.push(file)
end
end
else
end
end
是否可以根据 net-sftp 返回的结果创建这样的树?