papakay

papakay

Unzip .zip file to a folder using :zip module

I’m trying to unzip a .zip file to a specific folder path:

http://erlang.org/doc/man/zip.html#unzip-1

: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

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

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

OvermindDL1

Cool, thought so. :slight_smile:

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement