7017
|
1 ## Copyright (C) 2006, 2007 Sylvain Pelissier |
6049
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6049
|
9 ## |
|
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. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6049
|
18 |
|
19 ## -*- texinfo -*- |
6065
|
20 ## @deftypefn {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files}) |
|
21 ## @deftypefnx {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files}, @var{rootdir}) |
6049
|
22 ## Compress the list of files and/or directories specified in @var{files} |
|
23 ## into the archive @var{zipfiles} in the same directory. If @var{rootdir} |
|
24 ## is defined the @var{files} is located relative to @var{rootdir} rather |
|
25 ## than the current directory |
|
26 ## @seealso{unzip,tar} |
|
27 ## @end deftypefn |
|
28 |
|
29 ## Author: Sylvain Pelissier <sylvain.pelissier@gmail.com> |
|
30 |
|
31 function entries = zip (zipfile, files, rootdir) |
|
32 |
|
33 if (nargin != 3) |
|
34 rootdir = "./"; |
|
35 endif |
|
36 |
|
37 if (nargin == 2 || nargin == 3) |
|
38 rootdir = tilde_expand (rootdir); |
|
39 |
|
40 if (ischar (files)) |
|
41 files = cellstr (files); |
|
42 endif |
|
43 |
|
44 if (ischar (zipfile) && iscellstr (files)) |
|
45 |
|
46 cmd = sprintf ("cd %s; zip -r %s/%s %s", rootdir, pwd (), zipfile, |
|
47 sprintf (" %s", files{:})); |
|
48 |
|
49 [status, output] = system (cmd); |
|
50 |
|
51 if (status == 0) |
|
52 if (nargout > 0) |
|
53 cmd = sprintf ("unzip -Z -1 %s", zipfile); |
|
54 [status, entries] = system (cmd); |
|
55 if (status == 0) |
|
56 if (entries(end) == "\n") |
|
57 entries(end) = []; |
|
58 endif |
|
59 entries = cellstr (split (entries, "\n"))'; |
|
60 else |
|
61 error ("zip: zipinfo failed with exit status = %d", status); |
|
62 endif |
|
63 endif |
|
64 else |
|
65 error ("zip: zip failed with exit status = %d", status); |
|
66 endif |
|
67 |
|
68 else |
|
69 error ("zip: expecting all arguments to be character strings"); |
|
70 endif |
|
71 |
|
72 else |
|
73 print_usage (); |
|
74 endif |
|
75 |
|
76 endfunction |