gpt4 book ai didi

javascript - 使用 grunt 动态归档名称

转载 作者:行者123 更新时间:2023-11-28 08:05:30 25 4
gpt4 key购买 nike

我想根据 slides 文件夹中的目录创建多个 zip 文件夹。

是否可以使 zip 文件名与源文件夹相对应?我想存档名称需要是动态的,但我还没有找到任何适合这种需求的东西。

当前目录结构。

/
|
gruntFile.js
package.json
build/
slides/
|
|---slide1/slide1.txt
|---slide2/slide2.txt

所需的输出。

/
|
gruntFile.js
package.json
build/
|
|---slide1.zip
|---slide2.zip
slides/
|
|---slide1/slide1.txt
|---slide2/slide2.txt

gruntFile.js

/*global module:false*/
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
clean: {
archive: {
src: [ 'build' ]
}
},
compress: {
main: {
options: {
archive: 'build/archive.zip'
},
files: [
{src: ['slides/**'], dest: '', filter: 'isFile'}
]
}
},
});

grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');

grunt.registerTask(
'default',
'Clean the build directory and archive all files in the slides folder',
[ 'clean', 'compress' ]
);

};

最佳答案

是的,这应该是可能的。您可以通过path/**/*.txt获取目录中的每个文件。前两颗星 path/**/ 告诉 Grunt 查找每个子目录和 *.txt 中的每个文件。

compress: {
main: {
options: {
mode: 'zip'
},
files: [{
src: 'slides/**/*.txt',
dest: 'build/',
filter: 'isFile'
}]
}
}

关于javascript - 使用 grunt 动态归档名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24831800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com