简体   繁体   中英

nodejs zip archiver issue with directory path in windows

I'm having an issue with using zip.directory in Windows.

This is the file structure I'm trying to create:

. ├── file1.txt ├── file2.txt └── file3.txt

file2.txt and file3.txt are coming from a directory called dir .

Here is the code I have on my server:

const zip = archiver('zip')

zip.append('some text', { name: 'file1.txt' })   
zip.directory('dir/', '.')
zip.finalize()

This works fine on Mac. However, using the '.' to put everything in the same directory seems to not work on Windows (basically only file1.txt makes it into the zip).

The following, however, DOES work:

const zip = archiver('zip')

zip.append('some text', { name: 'file1.txt' })   
zip.directory('dir/', 'somename')
zip.finalize()

However, this gives a folder structure like this:

. ├── file1.txt └── somename ├── file2.txt └── file3.txt

which isn't really what I'm looking for. Is there a way around this?

I received an answer on the #node.js IRC channel.

Replacing this line:

zip.directory('dir/', '.')

with:

zip.directory('dir/', '../')

fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM