papakay
Unzip .zip file to a folder using :zip module
I’m trying to unzip a .zip file to a specific folder path:
:zip.unzip(zip_path, {cwd: "/tmp/test-extracted/"})
** (SyntaxError) test.exs:18: syntax error before: cwd
(elixir) lib/code.ex:677: Code.require_file/2
Please how can i extract to a specified folder?
Most Liked
voughtdq
First, "/tmp/test-extracted" is a binary and Erlang mostly expects charlists. So binaries/strings will need to be converted to charlists first.
cwd = "/tmp/test-extracted/"
cwd = to_charlist(cwd)
Charlists can be represented by surrounding the string part with single quotes: 'charlist'. That can be easy to forget, so it’s better to use the sigil and do something like this: ~c'charlist'.
Second, Erlang opts are usually represented like this: [{:someopt, true}, :someotheropt, {:somethingelse, ~c'thing'}].
I haven’t tested, but this should be pretty close to the correct form:
:zip.unzip(zip_path, [{:cwd, ~c'/tmp/test-extracted/'}]) # also represented by [cwd: ~c'...']
papakay
Thanks immensely @OvermindDL1.
The actual folder structure is a phoenix app 1.3 structure + uploads folder.
My original intension is to extract the zip inside the uploads folder.
Without cwd option, it extracts the zip content directly in the app root folder which is not what i want.
Thanks so much.
OvermindDL1
Cool, thought so. ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








