Groovy - 从 http URL 处理文件 [英] Groovy - File handling from http URL

查看:16
本文介绍了Groovy - 从 http URL 处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们其中一台服务器中的文件可以通过 http 访问.因此,当我们调出类似于以下内容的 url 时,我们会得到该位置的文件/目录列表:

The files in one of our servers can be accessed via http. So, when we bring up a url similar to the following, we get a list of files/directories in that location:

http://mytestserver/files/

从这个列表中,我只需要选择那些匹配正则表达式格式的文件.

From this list, I need to select only those files that match a regex format.

如果这是磁盘中的一个位置,我可以使用 eachFileMatch 方法并过滤我需要的文件.

If this was a location in the disk, I can make use of the method eachFileMatch and filter the files that I need.

有人可以帮助我如何从 http URL 执行此操作吗?

Can someone help me how we can do this from a http URL?

推荐答案

另一个版本的@tim_yates Answer using JSoup

Another version of @tim_yates Answer using JSoup

@Grab(group='org.jsoup', module='jsoup', version='1.7.3')
import org.jsoup.Jsoup
def (doc,files, dirs) = [Jsoup.connect('http://central.maven.org/maven2/com/bloidonia/groovy-stream/').get(),[],[]]
doc.select("pre > a").each{href ->
    def filename = href.text()
    filename.endsWith("/")?dirs.add(filename):files.add(filename)
}
println """DIRECTORIES : 
${dirs.join('
')}
FILES : 
${files.join('
')}
"""

这篇关于Groovy - 从 http URL 处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆