[英]JSZip: Checking if a zip folder contains a specific file
I currently have the following code:我目前有以下代码:
zip.folder("courses").forEach(function (relativePath, file) {
if (!file.dir) {
promises.push(zip.file(file.name).async("string"));
}
});
But I believe this assumes that the zip contains the "courses" folder, how do I check whether or not the zip contains a "courses" folder before the forEach loop?但我相信这假设 zip 包含“courses”文件夹,如何在 forEach 循环之前检查 zip 是否包含“courses”文件夹? Thanks!
谢谢!
You can use a regex with the function folder()
like:您可以将正则表达式与函数
folder()
例如:
var zip = new JSZip();
if(zip.folder(/courses/).length > 0) {
// Folder exists
} else {
// Folder doesn't exist
}
folder()
returns an array, see the documentation . folder()
返回一个数组,请参阅文档。 It is possible with file()
too.也可以使用
file()
。
For a specific file, you can try by the file name like following way.对于特定文件,您可以通过文件名尝试,如下所示。
var zip = new JSZip();
...................
if(zip.file(/csv/).length > 0 ){
// Do something
}
else if(zip.file(/pdf/).length > 0) {
// Do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.