简体   繁体   English

HTML / Javascript:获取给定目录中所有文件和子目录的列表

[英]HTML/Javascript: Getting a List of all files and subdirectories in a given directory

I am working on an interface that allows the to access the file system on the client side. 我正在开发一个允许访问客户端文件系统的接口。 The user should be able to browse through the file system, select a directory and my system will display list of files and sub-directories of the selected directory. 用户应该能够浏览文件系统,选择一个目录,我的系统将显示所选目录的文件列表和子目录。

I have tried using HTML5 File API, but that apparently only allows users to select files (not folders). 我曾尝试使用HTML5文件API,但显然只允许用户选择文件(而不是文件夹)。

Any pointers/help in this direction will be appreciated. 任何指针/帮助在这方面将不胜感激。

This cannot be done in JavaScript as it would be a potential security issue. 这不能在JavaScript中完成,因为它可能是一个潜在的安全问题。 Only files selected by the user via a file dialog can be accessed using JavaScript. 只能使用JavaScript访问用户通过文件对话框选择的文件。

Here's a pretty nice article on the File API if you haven't come across it yet. 下面是在一个相当不错的文章文件API ,如果你有没有碰到过它来呢。

If it's still an open issue, then let me give you a solution that might work for you. 如果它仍然是一个悬而未决的问题,那么让我给你一个可能适合你的解决方案。

HTML HTML

File input for selecting a directory: 用于选择目录的文件输入:

<input type="file" id="file-input" webkitdirectory="" directory=""/>

JavaScript JavaScript的

The following script collects all files from the given folder and from ALL sub folders. 以下脚本从给定文件夹和所有子文件夹中收集所有文件。 Even from sub-subfolders, etc. 甚至从子文件夹等

$("#file-input").on("change", function(e) {
    var thefiles = e.target.files;
    $.each(thefiles, function(i, item) {
        var thefile = item;
        var reader = new FileReader();
        reader.onload = function() {
            files.push(thefile);
        };
        reader.readAsArrayBuffer(thefile);
    });

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript正则表达式排除URL中给定目录的所有子目录 - Javascript regex to exclude all subdirectories of a given directory in a URL 在Google云端存储的特定目录中获取所有文件和子目录 - Getting all files and subdirectories inside a specific directory in Google cloud storage NodeJS-给定目录的完整路径,如何获取所有子目录的列表并检查文件是否异步存在? - NodeJS - Given a full path of a directory, how to get a list of all subdirectories and check if a file exists here asynchronously? 如何在目录中查找所有文件? (HTML JavaScript) - How to find all files in directory? (HTML JavaScript) 获取目录中所有文件的列表,包括。 Chrome WebServer上带有$ .GET和jQuery的子目录 - Get list of all files in a directory incl. subdirectories with $.GET & jQuery on Chrome WebServer Javascript列出网络服务器目录中的所有文件 - Javascript to list all files in directory on the webserver 如何使用 nodeJS 列出所有子目录和文件? - How to list all subdirectories and files using nodeJS? JS-从给定目录获取文件和目录的列表 - JS - getting a list of files and directories from a given directory 使用require-all从目录和子目录递归加载文件 - Recursively load files from directory and subdirectories with require-all 在 JavaScript 中获取给定日期范围内所有日期的列表 - Getting a list of all dates within a given date range in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM