我想根据slides文件夹中的目录创建多个压缩文件夹。
可以将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.txtgruntFile.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' ]
);
};发布于 2014-07-19 03:14:46
是的,这应该是可能的。您可以通过path/**/*.txt获取目录中的每个文件。前两颗星path/**/告诉Grunt查看每个文件的每个子目录和*.txt。
compress: {
main: {
options: {
mode: 'zip'
},
files: [{
src: 'slides/**/*.txt',
dest: 'build/',
filter: 'isFile'
}]
}
}https://stackoverflow.com/questions/24831800
复制相似问题