简体   繁体   English

如何访问特定文件夹以获取扩展名中的文件名

[英]How to access a specific folder to get file names within my extension

So i need to get names of files in my "db" folder, that i later need to use in my extension. 因此,我需要在“ db”文件夹中获取文件名,以后需要在扩展名中使用。 I searched on how to do this and I can get all file names from my root extension folder but not from any other. 我搜索了如何执行此操作,可以从根扩展文件夹中获取所有文件名,而不能从任何其他文件名中获取。

This is the code that gives back all file names from extension folder that i found from this question: How do I get a list of filenames in a subfolder of a Chrome extension? 这是从以下问题中找到的扩展文件夹中的所有文件名的代码: 如何在Chrome扩展的子文件夹中获取文件名列表?

chrome.runtime.getPackageDirectoryEntry(function(directoryEntry) {
var directoryReader = directoryEntry.createReader();
// List of DirectoryEntry and/or FileEntry objects.
var filenames = [];
(function readNext() {
    directoryReader.readEntries(function(entries) {
        if (entries.length) {
            for (var i = 0; i < entries.length; ++i) {
                filenames.push(entries[i].name);
            }
            readNext();
        } else {
            // No more entries, so all files in the directory are known.
            // Do something, e.g. print all file names:
            console.log(filenames);
        }
    });
})();
});

This is the code that is supposed to do what i want but i cant figure out how to implement it here 这是应该执行我想要的代码,但我无法弄清楚如何在此处实现它

directoryEntry.getDirectory('_locales', {}, function(subDirectoryEntry) {
var directoryReader = subDirectoryEntry.createReader();
// etc.. same code as in previous snippet.
});

The code I needed was this. 我需要的代码是这个。

chrome.runtime.getPackageDirectoryEntry(function(directoryEntry) {
    directoryEntry.getDirectory('index', {}, function(subDirectoryEntry) {
        var directoryReader = subDirectoryEntry.createReader();
        // List of DirectoryEntry and/or FileEntry objects.
        var filenames = [];
        (function readNext() {
            directoryReader.readEntries(function(entries) {
                if (entries.length) {
                    for (var i = 0; i < entries.length; ++i) {
                        filenames.push(entries[i].name);
                    }
                    readNext();
                } else {
                    // No more entries, so all files in the directory are known.
                    // Do something, e.g. print all file names:
                    console.log(filenames);
                }
            });
        })();
    });
});

暂无
暂无

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

相关问题 使用.get()检索服务器上文件夹中所有文件名的数组 - Using .get() to retrieve an array of all file names in a folder on my server Google脚本可在父文件夹中获取文件夹名称 - Google script to get folder names within a parent folder 如何在我的chrome扩展程序中获取其他chrome扩展程序的DOM访问 - How to Get DOM Access of other chrome extensions in My chrome extension 匹配嵌套在特定文件夹中的文件 - Match file within nested witin specific folder 如何在 Chrome 扩展程序中使用 Google People API 来获取我的联系人姓名、电子邮件、电话号码和组织 - How to use Google People API in Chrome extension to get my contacts names, emails, phone numbers and organizations 我想以谷歌浏览器扩展名访问下载的文件(在我的情况下为csv文件)并获取其内容 - I want to access downloaded file(csv file in my case) in google chrome extension and get content of that 如何找出扩展名 .pdf 的匹配文件名以及 URL 并在谷歌表中获取数据? - How to find out the matching file names for the extension .pdf along with the URL and get the data in google sheet? 如何使用jQuery / JavaScript将子文件夹中的所有文件名加载到我的安全网页中 - How to load all the file names from a sub folder into my secure web page, using jQuery/JavaScript 访问给定文件夹中的所有文件(文件系统访问 API) - Access all files within a given folder (The File System Access API) 如何将文件下载到Chrome扩展程序的扩展程序文件夹中? - How do I download a file to the extension folder in a Chrome extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM