[英]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.