[英]Gulp get a ls of a directory
I have a directory assets with a number of images inside. 我有一个目录资产,其中包含许多图像。 Inside my JavaScript code, I have an array, with the same list of images, that I use to preload everything.
在我的JavaScript代码中,我有一个带有相同图像列表的数组,可以用来预加载所有内容。 It means I have twice the same information, the list of images, both in my JavaScript and in my filesystem.
这意味着我在JavaScript和文件系统中都有两倍相同的信息(图像列表)。 I would like to have a gulp task to list all those images, and populate the array in JavaScript, with something like:
我想要一个gulp任务来列出所有这些图像,并使用类似以下内容的JavaScript填充数组:
var listFiles = require("list-files-in-folder"); var listFiles = require(“文件夹中的列表文件”); var images = listFiles("./assets/");
var images = listFiles(“ ./ assets /”);
Do you know of any plugin who does that? 你知道有谁做插件吗? Or a simple way to implement it maybe?
还是实现它的简单方法?
Assuming you're talking about nodejs, take a look at this 假设你在谈论的NodeJS,看看这个
var glob = require("glob")
// options is optional
glob("**/*.js", options, function (er, files) {
// files is an array of filenames.
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.