javascript 获取服务器上的目录列表使用JavaScript

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 获取服务器上的目录列表使用JavaScript相关的知识,希望对你有一定的参考价值。

## Access Directory Listing from Client Side
This code can list the contents of a directory on the
server that is serving a webpage running the code.

## Requirement
In order for this to work, Apache needs to be running `mod-autoindex`.

http://httpd.apache.org/docs/2.2/mod/mod_autoindex.xml

## Sorting and Formatting
Apache autoindexing allows basic sorting and formating by
appending a query string.

For instance, `http://someserver/somepath/somedir/?C=M;O=A` will 
sort the listing by modification date in ascending order.

* C=N sorts the directory by file name
* C=M sorts the directory by last-modified date, then file name
* C=S sorts the directory by size, then file name
* C=D sorts the directory by description, then file name
* O=A sorts the listing in Ascending Order
* O=D sorts the listing in Descending Order
* F=0 formats the listing as a simple list (not FancyIndexed)
* F=1 formats the listing as a FancyIndexed list
* F=2 formats the listing as an HTMLTable FancyIndexed list
* V=0 disables version sorting
* V=1 enables version sorting
* P=pattern lists only files matching the given pattern
var url = "http://someserver/somepath/somedir/?C=M;O=A";
$.get(url, (data) => 
{
    console.log(data);
    let listing = parseDirectoryListing(data);
    $('body').append(JSON.stringify(listing));
});

function parseDirectoryListing(text) 
{
    let docs = text
                 .match(/href="([\w]+)/g) // pull out the hrefs
                 .map((x) => x.replace('href="', '')); // clean up
    console.log(docs);
    return docs;
}   

以上是关于javascript 获取服务器上的目录列表使用JavaScript的主要内容,如果未能解决你的问题,请参考以下文章

获取中厨运行的目录列表

Pyspark:获取HDFS路径上的文件/目录列表

Unix命令获取远程主机上的目录列表

如何获取 .Net C# 上的 OPC UA 服务器列表?

获取 Bamboo 上的提交文件列表

thinkphp5获取ftp上的文件列表