gpt4 book ai didi

ruby-on-rails - Ruby: Net::SFTP 获取文件路径

转载 作者:太空宇宙 更新时间:2023-11-03 16:16:11 25 4
gpt4 key购买 nike

当我们使用 sftp.dir.entries 方法时,我们如何获取响应的文件完整路径?

我想要一个目录的文件内容(递归)。我使用 sftp.dir.entries 方法来列出存在的文件。我该如何获取内容?

最佳答案

也许您正在寻找 glob method :

Works as ::Dir.glob, matching (possibly recursively) all directory entries under path against pattern. If a block is given, matches will be yielded to the block as they are found; otherwise, they will be returned in an array when the method finishes.

Because working over an SFTP connection is always going to be slower than working purely locally, don't expect this method to perform with the same level of alacrity that ::Dir.glob does; it will work best for shallow directory hierarchies with relatively few directories, though it should be able to handle modest numbers of files in each directory.

因此,例如(也取自文档):

sftp.dir.glob("/remote/path", "**/*.rb")

应该返回远程机器上任何目录级别的所有 *.rb 文件。要获取所有文件,请改用"**/*"。另见 Dir class' glob method .

关于ruby-on-rails - Ruby: Net::SFTP 获取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44388911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com