Groovy - File handling from http URL

前端 未结 4 1843
旧巷少年郎
旧巷少年郎 2021-01-03 12:32

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:



        
4条回答
  •  -上瘾入骨i
    2021-01-03 13:24

    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('\n')}
    FILES : 
    ${files.join('\n')}
    """
    

提交回复
热议问题