I am trying to create the zip folder and ignore some particular files and folders like node_modules
, access.log
, and other hidden folders
.
in my case, I can able to ignore the .log
file but my code is not working for folder and hidden files/folder.
Please help how do I achieve the code and ignore the node_modules
folder and hidden files and folder including .log
files
as per the documentation page: https://www.npmjs.com/package/archiver
const fs = require("fs");
const archiver = require("archiver");
const output = fs.createWriteStream(__dirname + "/example.zip");
const archive = archiver("zip", {
zlib: { level: 9 }, // Sets the compression level.
});
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log("archiver has been finalized and the output file descriptor has closed.");
});
output.on("end", function () {
console.log("Data has been drained");
});
archive.on("warning", function (err) {
if (err.code === "ENOENT") {
// log warning
} else {
// throw error
throw err;
}
});
archive.on("error", function (err) {
throw err;
});
archive.pipe(output);
archive.glob("**", { cwd: __dirname, ignore: ["node_modules", "*.log"] }, {});
archive.finalize();
After quite a bit of digging found this link, which suggests that the folder name should be followed by a slash and two asterixis
opened 10:02PM - 12 Mar 15 UTC
closed 10:14PM - 12 Mar 15 UTC
I have a project that looks like this
```
ls foo/
- file0.js
- a/file1.js
- b/f… ile2.js
- c/file3.js
- d/file4.js
```
How do I write a [glob pattern][1] to **exclude the c & d folder** but get all other javascript files?
I imagine the solution would look similar to this:
```
glob('**/*.js, {ignore: ['c','d']}, function(e,f){console.log f})
```
I am wanting back
```
- file0.js
- a/file1.js
- b/file2.js
```
A shot in the dark, but does this work?
archive.glob("**", { cwd: __dirname, ignore: ["node_modules/**", "*.log"] }, {});
1 Like
rpg_digital:
cwd: __dirname
can we include multiple path ? in glob function ?
I can’t answer with any authority on this, maybe someone else here can better comment.
cwd is current working directory not directories, and actually look at the the link I gave you cwd has been omitted.
In the example they have selected multiple folders though.
glob('**/*.js', { ignore: '{c,d}/**' }, callback) // (folders c and d)
I wonder therefore if you could do something similar
archive.glob("**", { ignore: ["{path1, path2}/node_modules/**", "*.log"] }, {});
I’m sorry I can’t be more helpful. Guesswork at this point.
1 Like
system
Closed
November 25, 2022, 11:57pm
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.