0

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
Sergio Tapia
  • 9,173
  • 12
  • 35
  • 59

2 Answers2

0

Like this:

:zip.unzip(String.to_charlist(zip_path), cwd: "/tmp/test-extracted/")
Sergio Tapia
  • 9,173
  • 12
  • 35
  • 59
-1

There are several syntax errors here.

1) To call a function defined in a module, use Module:Function(Arguments).

zip:unzip(Zipfile).  % not zip.unzip()

2) Tokens begin with a lowercase character is called atoms, which are just some literals. You should use variables for the first argument of unzip/2.

Zipfile = "/path/to/your/zipfile.zip".
zip:unzip(Zipfile).

3) For the second argument of unzip/2, let's see how to understand the document you post:

unzip(Archive, Options) -> RetValue  

This is the function signature: two variable arguments and a return value

Archive = file:name() | binary()

The first argument should be of type file:name() or binary

Options = [Option]

Options argument should be a list.

Option = {file_list, FileList} |
    keep_old_files |
    verbose |
    memory |
    {file_filter, FileFilter} |
    {cwd, CWD} 

There are several forms of the list, including the one you need: {cwd, CWD}, which is a tuple, whose first element is atom cwd.

We have all the knowledge to call zip:unzip/2 correctly now:

Zipfile = "/path/to/your/zipfile.zip".
MyCwd = "/path/to/working_dir/".
zip:unzip(ZipPath, [{cwd, MyCwd}]). 
halfelf
  • 9,737
  • 13
  • 54
  • 63