1 ## Copyright (C) 2006-2012 Sylvain Pelissier
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files})
21 ## @deftypefnx {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files}, @var{rootdir})
22 ## Compress the list of files and/or directories specified in @var{files}
23 ## into the archive @var{zipfile} in the same directory. If @var{rootdir}
24 ## is defined the @var{files} are located relative to @var{rootdir} rather
25 ## than the current directory.
26 ## @seealso{unzip, bzip2, gzip, tar}
29 ## Author: Sylvain Pelissier <sylvain.pelissier@gmail.com>
31 function entries = zip (zipfile, files, rootdir = ".")
33 if (nargin != 2 && nargin != 3)
37 rootdir = tilde_expand (rootdir);
40 files = cellstr (files);
43 if (! ischar (zipfile) && ! iscellstr (files))
44 error ("zip: expecting all arguments to be character strings");
47 cmd = sprintf ("cd %s; zip -r %s/%s %s", rootdir, pwd (), zipfile,
48 sprintf (" %s", files{:}));
50 [status, output] = system (cmd);
53 error ("zip: zip failed with exit status = %d", status);
57 cmd = sprintf ("unzip -Z -1 %s", zipfile);
58 [status, entries] = system (cmd);
60 error ("zip: zipinfo failed with exit status = %d", status);
62 if (entries(end) == "\n")
65 entries = strsplit (entries, "\n");