Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add control over where files are appended inside zip irrespective of source path #117

@gacolitti

Description

@gacolitti

It would be really nice if I could specify where in the zip file I want another file to be added without needing that file to already be in a directory structure mirroring what I want in the zip file.

For example, if I have a zip file called file.zip and inside the zip file is the directory test and I want to add file2 inside the test folder of file.zip. As far as I can tell, I need to first move file2 into a folder named test and then I can use zip_append() to add it to the test folder of file.zip.

Using the example from the help file:

## Some files to zip up. We will run all this in the R session's
## temporary directory, to avoid messing up the user's workspace.
dir.create(tmp <- tempfile())
dir.create(file.path(tmp, "mydir"))
cat("first file", file = file.path(tmp, "mydir", "file1"))
cat("second file", file = file.path(tmp, "mydir", "file2"))

zipfile <- tempfile(fileext = ".zip")
zip::zip(zipfile, "mydir", root = tmp)

## List contents
zip_list(zipfile)

## Add another file outside "mydir"
cat("third file", file = file.path(tmp, "file3"))

# Say I want to add the file to "mydir" inside the zip file how can I do that here?
# As-is this will add file3 to the root of the zip file.

# zip_append(zipfile, "file3", root = tmp)
# zip_list(zipfile)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions