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